hello everybody,
I am new to this forum..I am trying to run a code..
I craeted a text file first with the name mmap.txt and wrote some lines in that....but I dont know why its not working It reads integer value for the position three times...but doesnt reads a character....can somebody please help me with that?
the code is:
I am new to this forum..I am trying to run a code..
I craeted a text file first with the name mmap.txt and wrote some lines in that....but I dont know why its not working It reads integer value for the position three times...but doesnt reads a character....can somebody please help me with that?
the code is:
Code:
#include<unistd.h>
#include<sys/mman.h>
#include<sys/types.h>
#include<fcntl.h>
#include<stdio.h>
#include<string.h>
int main()
{
int fd;
char *fileptr;
int i;
int x;
char ch;
fd=open("mmap.txt",O_RDWR);
fileptr=mmap(0,26,PROT_READ | PROT_WRITE,MAP_SHARED,fd,0);
for(i=0;i<3;i++)
{
printf("Enter the position in the file you want to change: ");
scanf("%d",&x);
printf("\n");
printf("Enter the new letter for that position: ");
scanf("%c",&ch);
printf("\n");
fileptr[x-1]=ch;
printf("\n");
}
munmap(fileptr,26);
close(fd);
return 1;
}