473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

How to return an array of strings and print it on my main() function

This is how my source code looks like:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int getInfo();
  4.  
  5. int main(void)
  6.     int name, firstName[10];
  7.     name = getInfo(firstName);
  8.     printf("Name: %s\n", firstName);
  9.     return 0;
  10. }
  11.  
  12. int getInfo()
  13. {
  14.     char firstName[10];
  15.     printf("\nNOTE: Answer the following information with one word only.\n");
  16.     printf("\nEnter first name: ");
  17.     scanf("%s",&firstName);
  18.     return firstName[10];
  19. }

the result of my program is not the one i'm expecting. what is wrong with my program?

when the program is run, it would look like this:

NOTE: Answer the following information with one word only.

Enter first name: Haifa
Name:B8~u(B~8~B(

T_T Help!!
Sep 18 '07 #1
1 1174
Ganon11
3,652 Expert 2GB
There are several errors I'm seeing. First and foremost, you have defined your function to accept no arguments, yet you are passing it an integer array. Next, you have an integer array called fullName? Should that be a character array? Next, your function returns an int, but you're trying to manipulate character arrays - this should return a char*.

Look over your code and rethink what you're trying to do, then come back if you still have questions.
Sep 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: buda | last post by:
Hi, given the following code, .... int main( void ) { char *a = { "abc", "def", "ghijkl", "o", "prs" }; // for example .... }
8
by: M. Moennigmann | last post by:
Dear all: I would like to write a function that opens a file, reads and stores data into an 2d array, and passes that array back to the caller (=main). The size of the array is not known before...
23
by: Nascimento | last post by:
Hello, How to I do to return a string as a result of a function. I wrote the following function: char prt_tralha(int num) { int i; char tralha;
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
44
by: svata | last post by:
Hello, I wonder how to resize such array of structures using realloc()? #include <stdio.h> #include <stdlib.h> #define FIRST 7 typedef struct { char *name;
19
by: Andrew Gentile | last post by:
Hello, I have been working on a program where I need to have a function return an array. I found out that C doesn't do this, so now I am trying to get the function to return a pointer to an...
17
by: Sara | last post by:
Hi, I'm having a problem with my program and I think it stems from me not understand how to call a function and return a int value to main. What I have to do is create a program that runs...
1
by: jef.d | last post by:
I am attempting to read through a text file & then update an HTML page table w/ the output from the text file (ie; statusing by table). What I want the code to do is read through the file, look...
27
by: junky_fellow | last post by:
Guys, Can I return 0, from main() ? Is this equivalent to exit(EXIT_SUCCESS) ? thanks for any help...
11
by: Rahul | last post by:
Hi Everyone, I have seen code in different styles like main(argc,argv) int argc; char **argv; { if(argc != 2) exit(1); else exit(0);
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.