Solved

Unix c reading file example and returning string value

Posted on 2007-04-01
3
2,235 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
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now