words counting in file like linux wc command in C
问题 I am trying to write something that works like the Linux command wc to count words, new lines and bytes in any kind of files and i can only use the C function read. I have written this code and i am getting the correct values for newlines and bytes but i am not getting the correct value for counted words. int bytes = 0; int words = 0; int newLine = 0; char buffer[1]; int file = open(myfile,O_RDONLY); if(file == -1){ printf("can not find :%s\n",myfile); } else{ char last = 'c'; while(read(file