Last active
August 29, 2015 14:06
-
-
Save joyeecheung/49360a0b050f3803d454 to your computer and use it in GitHub Desktop.
Read until the character `?`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main(void) { | |
char line[30000]; | |
char str[30000]; | |
FILE * pFile = fopen ("myfile.txt" , "r"); | |
/* Avoid buffer overflow by using fgets() */ | |
while (fgets(line, sizeof(line), pFile) != 0) { | |
if (sscanf(line, "%[^?]s", str) != 1) /* match [^?] */ | |
break; /* stop for this line if the pattern doesn't match */ | |
/* print the result and the length */ | |
printf("Found <<%s>>\n", str); | |
printf("The size of str is %d\n", strlen(str)); | |
} | |
int ch; /* faliure position */ | |
if ((ch = getc(pFile)) != EOF) | |
printf("Failed on character %d (%c)\n", ch, ch); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment