?
Solved

Unix c reading file example and returning string value

Posted on 2007-04-01
3
Medium Priority
?
2,283 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

801 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