Hey,
I actually try to learn about Unix-Network - Development, but I am pretty much a Newbie. (Not studying CS, yet...)
I am learning C++ just since 1 Month and therefore I do not want to go into C yet. (Would be confusing...)
Unfortunately, the book uses C which leads me to the first question:
I know you write this completely different in C++, but will the C++ Community kill me if I wrote code like this:
Code:
//ignore the german sentences, they are just stating what just happend wrongly
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]){
int fd;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP |S_IROTH;
char filename[] = "read.data";
char text[] = "0123\n""4567\n""89ab\n""cdef\n""ghij\n""klmn\n""opqr\n""stuv\n""wxyz\n";
ssize_t bw;
fd = open(filename,O_WRONLY | O_CREAT | O_TRUNC, mode);
if(fd < 0){
printf( "Kann die Datei '%s' nicht öffnen: %s\n",filename,strerror(errno) );
exit(EXIT_FAILURE);
}
bw = write(fd,text,strlen(text));
if(bw != strlen(text)){
printf("Konnte nur %zd Bytes schreiben. \n", bw);
exit(EXIT_FAILURE);
}
if(close( fd ) != 0){
printf("Konnte die Datei '%s' nicht schließen: %s\n", filename, strerror(errno));
exit(EXIT_FAILURE);
}
printf("Done\n");
return(EXIT_SUCCESS);
}
The second question is where read.data is created, I cannot find it in the filesystem, which leads me to the conclusion something went wrong. (Does not work with main.c either || I am using Mac)
Kind regards,
Niclas