?
Solved

Unix c reading file example and returning string value

Posted on 2007-04-01
3
Medium Priority
?
2,296 Views
Last Modified: 2012-06-22
unix c
I would like small  c program example that would
read 2 line of file and return it's value.
I hope you can return string value from main function.
thanks
0
Comment
Question by:jeromeb
1 Comment
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 18831945
Take a look at these standard functions (in header <stdio.h>) :

1) fopen : opens a file
        http://www.cplusplus.com/reference/clibrary/cstdio/fopen.html

2) fclose : closes a file
        http://www.cplusplus.com/reference/clibrary/cstdio/fclose.html

3) fgets : read a line from a file
        http://www.cplusplus.com/reference/clibrary/cstdio/fgets.html

4) printf : write output to the standard output (screen)
        http://www.cplusplus.com/reference/clibrary/cstdio/printf.html

Also, make sure to look at the examples at the bottom of each of those pages ... they show you how to use the functions.


>> I hope you can return string value from main function.

Not with a return statement - main has to return int. You can send it to standard output using printf (see earlier), or you can write it to a file.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question