fputs(tmp, fp);
fputs
writes the bytes until the terminating 0 byte.
while(fgets(line,50,fp) != NULL){
for(i=0;i<50;i++){
character = line[i];
character += offset;
tmp[i] = character;
}
you shift 50 char
s, regardless of how long the line that you read in was, and thus most of the time, there is no 0-byte in the tmp
buffer, thus fputs
often writes at least 50 bytes, some of which have nothing to do with what was in the file at that place, and beyond the buffer, which invokes undefined behaviour and might cause a crash.
You should check for the terminating 0-byte in the loop, probably even stopping at the newline is a good idea.
while(fgets(line,50,fp) != NULL){
for(i = 0; i < 50 && line[i] != 0 && line[i] != '\n'; i++){
character = line[i];
character += offset;
tmp[i] = character;
}
Note: the loop body would simpler be line[i] += offset;
.