my text.txt file
Code:
LDC 1,2 #444
LDC 1,2 #444
my program:
Code:
#include <stdio.h>
#include <string.h>
char file_array[10000];
void
readfile(char *file)
{
char ch;
int i = 0;
FILE *pfile = fopen(file, "r");
if (pfile == NULL)
{
puts("New Files");
}
else
{
while((ch = fgetc(pfile)) != EOF)
{
file_array[i] = ch;
i++;
}
file_array[i] = '\0';
fclose (pfile);
}
}
int main(int argc, char **argv)
{
char *filename = argv[1];
//char test_string[50]="PRINT 1,2";
char *sub_string;
readfile(filename);
printf("%s\n", strtok(file_array, " "));
while ( (sub_string=strtok(NULL, ",")) != NULL)
{
printf("%s\n", sub_string);
}
return 0;
}
at the moment my output is
a.out text.txt
LDC
1
2 #444
LDC 1
2 #444
i want to modify it so it prints out this
LDC
1
2
LDC
1
2
ignoring everything after and including the #
how do i do this?