Solved

Unix c reading file example and returning string value

Posted on 2007-04-01
3
2,280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

705 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