
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.