Solved

Newbie - Returning Strings ?

Posted on 1997-03-05
1
172 Views
Last Modified: 2012-05-04
I am just learning C. How do I return a string to a calling
function ?
I wish to call a function from main and have this function
prompt the user for a 'city code' and then search a
valid codes table. When the user enters a valid code
I wish to return this string value to main and then pass
it to subsequent functions.
Thanks in advance...Neil (carsonn@psac.com)
0
Comment
Question by:carsonn
1 Comment
 
LVL 1

Accepted Solution

by:
Michel021497 earned 50 total points
ID: 1249412
This is the layout of a function returning a string.
In the function you create a string s.
At the end of the function you return s.

char *function()
{
   char *s;
   your code
   return s
}
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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 and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

747 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

13 Experts available now in Live!

Get 1:1 Help Now