Reputation: 495
I want to read from file a number and increase the number than write it to file. I want to use read/write not fscanf/fprintf .I tried to change integer to string but i found on Google that the itoa doesn't exist in linux . This is my code :
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
main(int argc,char *argv[]){
int f;
f=open(argv[1],O_RDWR);
char c[10];
read(f,c,10);
int ceva=atoi(c);
printf("%d ",ceva);
ceva++;
//itoa (ceva,c,10);
lseek(f,0,SEEK_SET);
write(f,ceva,sizeof(int));
}
Upvotes: 0
Views: 819
Reputation: 6214
What do you have against fprintf
? You need to convert the integer to a string somehow. Another option would be to use snprintf
to convert the integer to a string then write
the string.
Upvotes: 3