Long time no C.
Well, this is a simple program just to translate ASCII codes to simple text.
The program ran without errors, well good enough. But I'm amazed to see how many times the loop in it ran.
Here's the code:
I used fscanf assuming that it wouldn't read whitespace characters as the message would be in form of:Code:#include<stdio.h>
int main()
{
FILE* fptr;
int n=0;
char msg[100];
int spaces=0; //whitespace
int norm=0; //any other characters
fptr= fopen("decipher.txt","r");
fscanf(fptr,"%d",&msg[0]);
printf("\nThis is what has been said:\n");
while(msg[n]!=EOF)
{
n++;
if(fscanf(fptr,"%d",&msg[n])==0)
spaces++;
else
norm++;
}
printf("%d\n%d\n%d\n",n,spaces,norm);
puts(msg);
return 0;
}
Even modified the file but it would return the same value for n.Quote:
75 105 108 108 32 109 101 32 116 101 110 100 101 114 108 121 32 109 121 32 108 111 118 101 46 4
The spaces and norms wouldn't add up equal to n.Quote:
114 97 110 100
And as usual please do point out any sort of stupidity :p