Hi guys, i like to thank all who has helped me so far. I managed to come up with some sort of code, to find the invalid string. e.g -8ha .
However im having problems getting it to print whether is it a invalid string once only. Also if there is a number in the invalid string it will print the number out too.
Also, if it is a negative number, the program will print it as invalid string too.
/*the output is .
Contents of file : 12 3 + * -79 -8ha
12 number
3 number
+ not number
* not number
-79 invalid
invalid
invalid
number
-8ha invalid
invalid
number
*/
i managed to print the positive number and operator correctly,
however i just cant seem to print the negative number and invalid string correctly.
can some1 help pls?
thanks in advance...
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main()
{
FILE * mFile;
char string[100]; /* Input line from file */
char st[100]; /* Temporary storage for the line */
char nt[4];
char *tokenPtr;
mFile = fopen ("myfile.txt" , "r");
if (mFile == NULL) { /* If there was a problem, show the error */
perror ("Error opening file");
}
else {
fgets (string , 100 , mFile);
printf("The original line: >%s<\n", string);
strcpy(st, string);
tokenPtr = strtok(st, " \n");
while( tokenPtr != …