Easiest thing to do is read the entire line in, then truncate if there a ;
.
char buffer[1024], * p ;
if ( fgets(buffer, sizeof(buffer), fin) )
{
if (( p= strchr( buffer, ';' ))) { *p = '\0' ; } // chop off ; and anything after
for ( p= buffer ; ( * p ) ; ++ p )
{
char c= * p ;
// do what you want with each character c here.
}
}
When you do the read, buffer will initially contain:
"read this in ; skip from semicolon on to new line\n\0"
After you find the ;
in the line and stick a '\0'
there, the buffer looks like:
"read this in \0 skip from semicolon on to new line\n\0"
So the for loop starts at r
and stops at the first \0
.