D
devkays
So I wrote the following program in C, but I'm not sure that it is doing what it is supposed to do. I verified the source code against the solution in the back of the book and I'm pasting here what the solution in the back of the book is.
#include<stdio.h>
#include<stdlib.h>
int main(){
int ch;
int at_beginning = 1;
int line = 0;
while( (ch==getchar())!= EOF){
if(at_beginning == 1){
at_beginning = 0;
line+=1;
printf("%d ", line);
}
putchar(ch);
if(ch == '\n')
at_beginning = 1;
}
return EXIT_SUCCESS;
}
#include<stdio.h>
#include<stdlib.h>
int main(){
int ch;
int at_beginning = 1;
int line = 0;
while( (ch==getchar())!= EOF){
if(at_beginning == 1){
at_beginning = 0;
line+=1;
printf("%d ", line);
}
putchar(ch);
if(ch == '\n')
at_beginning = 1;
}
return EXIT_SUCCESS;
}