I want to input text from stdin and then display it on the screen, while numbering the lines. The last part of my program is not working, I don't know how to use the read()
function correctly.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <io.h>
#include <string.h>
int main()
{
char s[201];
int i=0, f = open("text.dat", O_RDWR | O_CREAT | O_TRUNC);
while (fgets(s,200,stdin) != NULL)
write(f,s,strlen(s));
char *buf;
while (read(f,buf,200) > 0)
printf("%d %s", i++, *buf);
close(f);
return 0;
}