LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2003, 12:19 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
C can 't return a character array


I have already soved this. How do I delete this entry.
I guess I have to erase all text, but that would leave a dangling entry with no topic.

===============================
root:~# gcc -o test-fscanf2 test-fscanf2.c

test-fscanf2.c: In function `find_ethernet_card_address':
test-fscanf2.c:32: warning: return makes integer from pointer without a cast

It is complaining on line 32
32 return (ethernet_mac_address);

When I commented line 32, I can compile, but when I run
it gives me "segmentation fault" error.

I wanted to return ethernet_mac_address, so I am back with
returning a character array from a function call.

=================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


char find_ethernet_card_address(var1, var2, var3, var4, ethernet_mac_address)
char var1[17], var2[17], var3[17], var4[17];
char ethernet_mac_address[17];
{
FILE *file_pointer, *fopen();

file_pointer = popen("ifconfig", "r");
fscanf(file_pointer, "%s%s%s%s%s", &var1, &var2, &var3, &var4, &ethernet_mac_address);

printf ("var1 = %s\n", var1);
printf ("var2 = %s\n", var2);
printf ("var3 = %s\n", var3);
printf ("var4 = %s\n", var4);
printf ("ethernet_mac_address = %s\n",
ethernet_mac_address);
fclose (file_pointer);
32 return (ethernet_mac_address);
}

main()
{

char var1[17];
char var2[17];
char var3[17];
char var4[17];
char ethernet_mac_address[17];
int result = 99;

find_ethernet_card_address(var1, var2, var3, var4, ethernet_mac_address);

}

Last edited by Linh; 06-13-2003 at 05:20 PM.
 
Old 06-13-2003, 03:07 PM   #2
Wynd
Member
 
Registered: Jul 2001
Distribution: Slackware 12
Posts: 511

Rep: Reputation: 32
Just a question, but if you're printing out the variable and assigning the string in main() the value of it, do you need to return it? Seems to me you'd already have the value...
 
Old 06-13-2003, 09:43 PM   #3
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Probably because the address get's distroyed after the function ends.
 
Old 06-16-2003, 10:16 PM   #4
chandan
Member
 
Registered: Feb 2003
Location: Bangalore, India
Distribution: Fedora Core 2
Posts: 60

Rep: Reputation: 15
This is call by reference
You neednot return the value
 
Old 06-17-2003, 06:52 AM   #5
yuray
Member
 
Registered: Apr 2003
Location: Russia, Khotkovo
Distribution: Debian
Posts: 146

Rep: Reputation: 15
was:
char find_ethernet_card_address(var1, var2, var3, var4, ethernet_mac_address)

MUST:
char *find_ethernet_card_address(var1, var2, var3, var4, ethernet_mac_address)
 
Old 06-18-2003, 04:58 AM   #6
nowonmai
Member
 
Registered: Jun 2003
Posts: 481

Rep: Reputation: 48
Re: C can 't return a character array

Quote:
Originally posted by Linh
I have already soved this. How do I delete this entry.
I guess I have to erase all text, but that would leave a dangling entry with no topic.
might I suggest that you leave it... it might help other people who are having similar problems
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SIGSEGV: Array of character pointers?? usercsr Programming 2 04-23-2005 11:34 AM
pattern file with no return character ksun Linux - Newbie 1 12-28-2004 06:40 PM
How to return values into an array using awk Helene Programming 1 05-01-2004 10:05 PM
function won ' t return character array word Linh Programming 1 07-31-2003 06:11 PM
Cannot pass and return a character array Linh Programming 1 06-12-2003 04:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration