I'm in a class where the professor has just thrown us into the world of C with no help at all. So I would really appreciate any help anyone can give. I know Java and Visual Basic pretty well, so I'm not completely new and lost, I just don't understand what's going on here because I don't know the syntax.
The assingment he has given us this week is to put the chars of the input he will be testing our project with into an array and then taking them from that array and turning them into hex based on the ASCII table.
For example:
This is \t \t a test of the system.
Should turn into
54 68 69 73 20 69 73 09 09 61 20 74 65 73 74 20 6F 66 20 74 68 65 20 73 79 73 74 65 6D
Here is the code I have so far. This could all be horribly wrong because I have taken a lot of this from different forums and webpages all over the web. If anyone has any help, any changes, whatever, I would be glad to hear it!
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(int argc, char **argv)
{
FILE *fp;
int c;
char temp;
int num[1000];
int j = 0;
if (argc != 2) {
fprintf(stderr, "%s input.txt\n", argv[0]);
exit(1);
}
if (!(fp = fopen(argv[1], "r"))) {
perror(argv[1]);
exit(1);
}
while(!feof(fp)){
temp = fgetc(fp);
num[j] = temp - '0';
fprintf(stdout, "%n", num[j]);
j++;
printf("%hhX", num[j]);
}
system("PAUSE");
fclose(fp);
return 0;
}