I'm trying to write a C program that take input and output using system calls (read
and write
). However, I also want to convert using sscanf
. The program will input a starting and ending value and will count to that ending value. I'm trying to use sscanf
to convert.
int main(int argc, char **argv){
char beg[5];
char stop[5];
int i, start, end;
write(1, "Starting value: ", 16);
read(0, beg, 4);
sscanf(beg,"%d",&start);
write(1, "Ending value: ", 14);
read(0, stop, 4);
sscanf(stop,"%d",&end);
int dif = end - start;
if (dif >= 0){
for (i = start; i <= end; i++){
write(1, &i, sizeof(i));
}
write(1, "\n", 1);
}
return 0;
}
Desired output:
Starting value: 1
Ending value: 4
1 2 3 4
However, nothing prints for the count (it works if I used printf("%d ", i);
)