TheButcher
Programmer
Be prepared......I'm a newbie.
I have a problem. I have a file I have to read in and parse it depending upon white space.
Ex) #comment
I read this line in using fgets() into a string array. I then use an output pointer to do a string tokenizer.
After the eliminating the frontal white space(' ', \t, \n, \r), I want to check the 1st line to see if it is a comment. I can do this with an array(use array[0] to see if is '#'). But strtok() can only be done with a pointer. How do I check the 1st character of a pointer?
Maybe there is a better way to do this, but here is what I got.
while((!feof(FreadIn)) && (!(FileLine[0] == '.')))
{
fgets(FileLine, 100, FreadIn);
if ((FileLine[0] == ' ') || (FileLine[0] == '\t') || (FileLine[0] == '\n'))
{
strcpy(temp1, FileLine);
output1 = strtok(temp1, whitespace);
fputs(output1, Fintermediate);
fputc(' ', Fintermediate);
while((output1 = strtok(NULL, whitespace)) != NULL)
{
fputs(output1, Fintermediate);
fputc(' ', Fintermediate);
}
fputc(newLine, Fintermediate);
}
else if(FileLine[0] == '#')
{
fputs(FileLine, Fintermediate);
}
else if((FileLine[0] == '.') && (FileLine[1] == 'P'))
{
fputs(FileLine, Fintermediate);
}
1st...if there is space, tokenize it.
2nd...if 1st char is #, write it to file
3rd...if it is ".PROGRAM" go on to next section (not shown)
Thanks in advance!
I have a problem. I have a file I have to read in and parse it depending upon white space.
Ex) #comment
I read this line in using fgets() into a string array. I then use an output pointer to do a string tokenizer.
After the eliminating the frontal white space(' ', \t, \n, \r), I want to check the 1st line to see if it is a comment. I can do this with an array(use array[0] to see if is '#'). But strtok() can only be done with a pointer. How do I check the 1st character of a pointer?
Maybe there is a better way to do this, but here is what I got.
while((!feof(FreadIn)) && (!(FileLine[0] == '.')))
{
fgets(FileLine, 100, FreadIn);
if ((FileLine[0] == ' ') || (FileLine[0] == '\t') || (FileLine[0] == '\n'))
{
strcpy(temp1, FileLine);
output1 = strtok(temp1, whitespace);
fputs(output1, Fintermediate);
fputc(' ', Fintermediate);
while((output1 = strtok(NULL, whitespace)) != NULL)
{
fputs(output1, Fintermediate);
fputc(' ', Fintermediate);
}
fputc(newLine, Fintermediate);
}
else if(FileLine[0] == '#')
{
fputs(FileLine, Fintermediate);
}
else if((FileLine[0] == '.') && (FileLine[1] == 'P'))
{
fputs(FileLine, Fintermediate);
}
1st...if there is space, tokenize it.
2nd...if 1st char is #, write it to file
3rd...if it is ".PROGRAM" go on to next section (not shown)
Thanks in advance!