I have my fopen set up like this. I have tried my fopen with both "t" and without "t". For some reason my fprintf is printing out ^M which are carriage returns. How do I stop frpintf from doing this? I want to just use the normal new line character.
FILE *outputfp;
// +5 to have space for .txt and terminator
char *fname = calloc(strlen(argv[1]) + 5, sizeof(fname[0]));
strcpy(fname, argv[1]);
strcat(fname, ".lst");
outputfp = fopen (fname, "w");
//printf("Above error message\n");
if (outputfp == NULL)
{
printf("Error while opening the file.\n");
return 1;
}
fprintf(outputfp, "hello\n");
http://en.wikipedia.org/wiki/Control_character http://www.pixhost.org/show/4770/21527928_cr.jpeg
I'm using Fedora and I compile this with gcc
Update:
if((int)line[0] == 46)
{
//printf("You have a period \n");
//printf("%s", line);
for(i = 0; i < 80; i++)
{
//fprintf(outputfp,"%c", line[i]);
if (isprint((unsigned char)line[i]) || isspace((unsigned char)line[i]))
{
printf("%c", line[i]);
//fprintf(outputfp, "\n Print something \n");
fprintf(outputfp,"%c", line[i]);
}
//printf("%c", line[i]);
//printf(" %d %c ", line[i], line[i]);
}
//fprintf(outputfp, "\n ");
//printf(" ------------------------\n");
memset(line, 0, 80);
comment_flag = 1;
}
//sscanf(line, "%s %s %x", label, mneumonic , &start_address);
//printf("start_address %d \n", start_address);
printf("%x %s %s %s %x\n", start_address, label, mneumonic, operand, start_address);
fprintf(outputfp, "%x %s %s %s %x\n", start_address, label, mneumonic, operand, start_address);
It actually looks like this is the line it doesn't like. I wanna cycle through my whole array before it prints a new line character.
fprintf(outputfp,"%c", line[i]);
Update:
char line[80] = {0};
while(fgets(line, 80, input) != NULL)
fopen(fname, "wb");
instead of just"w"
? I'm not sure how you got it into this mode. – Michael