Reading string by char till end of line C/C++ -


how read string 1 char @ time, , stop when reach end of line? i'am using fgetc function read file , put chars array (latter change array malloc), can't figure out how stop when end of line reached

tried (c variable char file):

if(c=="\0") 

but gives error cant compare pointer integer

file looks (the length of words unknown):

one 2 3 

so here comes questions: 1) can compare c \0 \0 2 symbols (\ , 0) or counted 1 (same question \n) 2) maybe should use \n ? 3) if suggestions above wrong suggest (note must read string 1 char @ time)

(note pretty new c++(and programming self))

you want use single quotes:

if(c=='\0') 

double quotes (") strings, sequences of characters. single quotes (') individual characters.

however, end-of-line represented newline character, '\n'.

note in both cases, backslash not part of character, way represent special characters. using backslashes can represent various unprintable characters , characters otherwise confuse compiler.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -