i am trying to write 2 strings to a file ,however after each string has been written i want to start a new line , i know that "\n" is the newline character however whenever i try and fwrite this it wont work. here is my code:
the file test.txt currently shows 0000 11111 , however i want it to show:Code:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
FILE write(FILE *f, char *operand)
{
fwrite(operand, 1, (strlen(operand)+1), bo);
}
void test()
{
FILE *f;
if ( ( f = fopen("test.txt", "r+b" ) ) == NULL) {
printf( "File Cannot Be Opened\n" );
}
int a = 1;
int b = 2;
if( a == 1){
char a[20];
strncpy( a, "00000", 20 ) ;
write(f,a);
}
if( b == 2){
char b[20];
strncpy( b, "11111", 20 ) ;
write(f,b);
}
}
int main(void)
{
test();
}
00000
11111
how can i put newlines in? thanks.