CSCI 463 Assignment 1: Understanding Constants and sscanf() in C, Assignments of Computer Architecture and Organization

The instructions and code for assignment 1 of csci 463, a computer science course in spring-2007. The assignment focuses on understanding how integer, float, and character constants are stored and retrieved in a computer's memory, as well as studying the sscanf() macro. Students are required to compile, run, and analyze the output of the provided c program.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-pyi
koofers-user-pyi 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCI 463 Assignment 1 Due: 01/26/07 (2nd Week)
Spring-2007 (50 pts)
Integer, Float and Character constants:
1) How they are stored in the computer=s memory
2) How they are retrieved
3) Study of sscanf() as a macro
Consider the following program in C:
#include<stdio.h>
#include<string.h>
#include<math.h>
void main()
{ int i = pow(2,15)-1, m, n;
unsigned j = pow(2,16)-1;
long k = pow(2,31)-1;
int bYear, bMonth, bDay;
float pAge;
char inBuffer[40] = {"Thomas Jefferson 1743 04 13 57.9"}, *p = inBuffer;
char first[10], last[10];
printf("\n %d, %x", i, i);
printf("\n %d, %x", i+1, i+1);
printf("\n %u, %x", j, j);
printf("\n %u, %x", j+2, j+2);
printf("\n %ld, %x", k, k);
printf("\n ld, %x", k+3, k+3);
m = sizeof(inBuffer);
n = strlen(inBuffer);
printf("\n sizeof(inBuffer) = %d, strlen(inBuffer) = %d", m, n);
printf("\n ");
for (m=n/2+1; m<=n; m++)
printf("*(p+m) as characters = %c \n",*(p+m));
printf("\n ");
for (m=n/2+1; m<=n; m++)
printf("*(p+m) as hexadecimals = %x \n",*(p+m));
printf("\n *p in hex = %x, *p as character = %c", *p, *p);
sscanf(inBuffer,"%s %s %d %d %d %f %*c",first,last,&bYear,&bMonth,&bDay,&pAge);
printf("\n Name: %s %s, Born: %d %d %d, Became President at age: %4.1f\n",
first,last,bYear,bMonth,bDay,pAge);
}
1. Copy the above program into your directory as Prog01.c.
2. Compile & link/edit it to get your Prog01.exe.
3. Run Prog01.exe and save its output as Prog01.out by: Prog01 > Prog01.out.
4. Study your output, Prog01.out, answer the questions on Page 2, and hand in Page 2.
pf3

Partial preview of the text

Download CSCI 463 Assignment 1: Understanding Constants and sscanf() in C and more Assignments Computer Architecture and Organization in PDF only on Docsity!

CSCI 463 Assignment 1 Due: 01 / 26 /07 (2nd Week)

Spring- 2007 (50 pts)

**Integer, Float and Character constants:

  1. How they are stored in the computer=s memory
  2. How they are retrieved
  3. Study of sscanf() as a macro Consider the following program in C:** #include<stdio.h> #include<string.h> #include<math.h> void main() { int i = pow(2,15)-1, m, n; unsigned j = pow(2,16)-1; long k = pow(2,31)-1; int bYear, bMonth, bDay; float pAge; char inBuffer[40] = {"Thomas Jefferson 1743 04 13 57.9"}, p = inBuffer; char first[10], last[10]; printf("\n %d, %x", i, i); printf("\n %d, %x", i+1, i+1); printf("\n %u, %x", j, j); printf("\n %u, %x", j+2, j+2); printf("\n %ld, %x", k, k); printf("\n ld, %x", k+3, k+3); m = sizeof(inBuffer); n = strlen(inBuffer); printf("\n sizeof(inBuffer) = %d, strlen(inBuffer) = %d", m, n); printf("\n "); for (m=n/2+1; m<=n; m++) printf("(p+m) as characters = %c \n",(p+m)); printf("\n "); for (m=n/2+1; m<=n; m++) printf("(p+m) as hexadecimals = %x \n",*(p+m)); printf("\n *p in hex = %x, *p as character = %c", *p, p); sscanf(inBuffer,"%s %s %d %d %d %f %c",first,last,&bYear,&bMonth,&bDay,&pAge); printf("\n Name: %s %s, Born: %d %d %d, Became President at age: %4.1f\n", first,last,bYear,bMonth,bDay,pAge); }
  1. Copy the above program into your directory as Prog01.c.
  2. Compile & link/edit it to get your Prog01.exe.
  3. Run Prog01.exe and save its output as Prog01.out by: Prog01 > Prog01.out.
  4. Study your output, Prog01.out, answer the questions on Page 2, and hand in Page 2.

Due: 01 /26/07 (2nd Week)

CSCI 463 Assignment 1 Name:_______________,____________

Spring-2007 (50 pts) (Last:spell) (First)

  1. printf( " \n %d, %x", i, i); will display: ____________, _____________
  2. printf("\n %d, %x", i+1, i+1); will display: _____________, _____________
  3. printf("\n %u, %x", j, j); will display: ____________, _____________
  4. printf("\n %u, %x", j+2, j+2); will display: _____________, _____________
  5. printf("\n %ld, %x", k, k); will display: __________________, ___________________
    1. printf("\n %ld, %x", k+3, k+3); will display: _________________,

m = sizeof(inBuffer); n = strlen(inBuffer);

  1. printf("\n %d, %d", m, n); will display: _____, ____ m = n / 2 + 1;
  2. printf("\n %c",*(p+m)); will display: ____
  3. printf("\n %x",*(p+m)); will display: ____
  4. printf("\n %x, %c", *p, p); will display: ______, _______ Finally, when the following instruction is executed: sscanf(inBuffer,"%s %s %d %d %d %f %c",first,last,&bYear,&bMonth,&bDay,&pAge);
  5. printf(A\n %c, %x@, first[0], first[0]); will display: _____, _____
  6. printf(A\n %d, %x@, bYear, bYear); will display: _____, _____
  7. printf(A\n %f@, pAge); will display: ________

Hand in