I/O on File


 
Thread Tools Search this Thread
Top Forums Programming I/O on File
# 1  
Old 03-19-2010
I/O on File

Hello everybody... In my client - server application I decided to save user name and password in a file by the system call creat(), write().
Code:
 recv(i,buf,sizeof(buf),0);
             result=write(ds_user,buf,sizeof(buf));
                          if (result==-1){
                              printf("error on write");
                              exit(1);
                            }

Now there is a problem in the client-autentication and the next registration-autentication becouse I don't know very well how to manage the file:
This is the autentication code but it's not work
Code:
recv(i,buf,sizeof(buf),0);
char buffer[40];
result1=(ds_user,buffer,40);
printf("%s",buffer);
if (result1==-1){
   printf("error on read");
   exit(1);
 }
   if (strcmp(buf,buffer)==0){
    send(i,"/ok",MAX,0);

where the problem?? is there someone that has got some good example with I/O file?? For example if I want to start reading or writing not at the begin but for example in the middle of the file or in the second row or at the fifth word???
Thank you very much!
# 2  
Old 03-20-2010
This line:
Code:
result1=(ds_user,buffer,40);

...what is it even supposed to do? I can't tell. It looks vaguely like a function call but there's no function! I'm shocked it compiles.

For file I/O, see man pages for fopen, fclose, and fgets. if it's a text file it's best to read line by line since you'll have no idea what line you'll end up in when you seek.
# 3  
Old 03-20-2010
Hi.
Quote:
Originally Posted by Corona688
... It looks vaguely like a function call but there's no function! I'm shocked it compiles.
I think comma operators in a list (essentially) throw away everything except the right-most value ... cheers, drl
# 4  
Old 03-20-2010
Ok, first I must read a lot of slide in which there is I/O file, after that I'll start to write code!;-)
# 5  
Old 03-20-2010
You could also read the manual pages for the functions I suggested, they will be helpful.
# 6  
Old 03-20-2010
Quote:
Originally Posted by drl
Hi.

I think comma operators in a list (essentially) throw away everything except the right-most value ... cheers, drl
It is part of the C standard; commas are sequence points. Plus, the OP forgot the write(
# 7  
Old 03-20-2010
Hi, jim.
Quote:
Originally Posted by jim mcnamara
... part of the C standard; commas are sequence points ...
Thanks for reply -- it's good to know and use the correct terminology.

For those wishing to read more, see Sequence point - Wikipedia, the free encyclopedia ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies
Login or Register to Ask a Question