c - Formatting file inputted text in char array? -


i have file.txt contains string of text. lets string is, without quotations "xdfs2\0dj\0\0aj"

first put text char array, have accomplished using fopen , fread input text char *workingarray;

my problem comes in form of trying print array. (using printf) want print array character character, each time reads '\0' want go new line.. output of workingarray be..

xdfs2  dj  aj 

i'm trying accomplish in way right now..

for( i=0; <= length; i++ ) {     if( workingarray[i] = '\0' ) {         printf("\n");     } else {         printf( "%c", workingarray[i]);     } } 

now doesn't work because doesn't see first \0's '\0' '\' , '0', 2 separate fields in array. i've tried searching '\' using '\\' in order compensate fact it's escape sequence gives me segmentation fault , core dumb when trying run it.

i've tried making second array based off of first takes '\' first , make '\0' in second while ignoring 0 in first instead, this.

int k = 0 length = sizeof(workingarray);  for(i=0; <= length; i++) {     if( workingarray[i] = '\\') {         newarray[i-k] = '\0';         k++;     } else if ( workingarray[i] = '0' ) {         return;     } else {         newarray[i-k] = workingarray[i];     } } 

long story short is.. i'm not sure how this. how can input string of text file (the entire file, not part of it) , print string out whilst creating new lines every \0 in string?

if have actual '\\' , '0' in array instead of nul, do

for( i=0; < length; i++ ) {     if( workingarray[i] == '\\' && workingarray[i+1] == '0' ) {         i++;         printf("\n");     } else {         printf( "%c", workingarray[i]);     } } 

note need use < in for-loop instead of <=, , comparison needs use == , not =.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -