Solved

Unix c reading file example and returning string value

Posted on 2007-04-01
3
2,262 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

792 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