C program to write 2 -D array into file (one string on each line of the file)
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
int main ()
{
int fd;
char a[10][20] =
{"google", "aricent", "sparrow",
"jumanji"};
fd =
open("/home/labuser/open_file", O_CREAT | O_RDWR | O_SYNC, 0755);
if (fd < 0) {
return 1;
}
a[0][strlen(a[0])] = '\n';
write(fd, a[0],
sizeof(a[0]));
a[1][strlen(a[1])] = '\n';
write(fd, a[1],
sizeof(a[1]));
a[2][strlen(a[2])] = '\n';
write(fd, a[2],
sizeof(a[2]));
a[3][strlen(a[3])] = '\n';
write(fd, a[3],
sizeof(a[3]));
}