Is this program doing what is supposed to do ?

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;
}
 
I

Ian Collins

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.
Well what is it supposed to do?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top