Q:

Replacing characters in file in c

I am writing single program, which should replace 10th,11th and 12th character in file with "A" . Problem is, that my program will just write those A's at the end of the file. Could you,please help me? Thanks in advance.
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

int main(int argc, char **argv)
{
int des,l,k;
char buf;

des = open("tmp",O_CREAT|O_APPEND|O_RDWR,S_IRUSR|S_IWUSR);
if (l = lseek(des,10L,SEEK_SET)== -1)
    {
        perror("lseek()");
        return (des);
    }                   //get to the position 10
else
{   
    for (k=0;k<3;k++)
        {
            write(des,"A",1);
        }
}                       //write AAA
read(des,&buf,1);
printf("%c",buf);       //checking
return 0;

}

A:

You used O_APPEND, so the data is appended at the end of the file.
Removing it from the argument of open worked.

