LinuxQuestions.org
Visit the LQ Articles and Editorials section
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-12-2003, 03:59 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Cannot pass and return a character array


gcc -o read-file-inter0 read-file-inter0.c

read-file-inter0.c: In function `read_file_nic':
read-file-inter0.c:22: subscripted value is neither array nor pointer
read-file-inter0.c:23: subscripted value is neither array nor pointer
read-file-inter0.c:27: subscripted value is neither array nor pointer
read-file-inter0.c:29: subscripted value is neither array nor pointer
read-file-inter0.c:30: subscripted value is neither array nor pointer
read-file-inter0.c:33: warning: passing arg 1 of `strcmp' makes pointer from integer without a cast
read-file-inter0.c: In function `main':
read-file-inter0.c:50: incompatible types in assignment
read-file-inter0.c:51: incompatible types in assignment

/**********************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

char read_file_nic(file_name, word)
/* char word[17]; */
{
FILE *inter0, *inter1, *fopen();
int i = 0;
char single_char;
/* char word[17]; */
int result = 99;

inter0 = fopen(file_name, "r");

single_char = getc(inter0); /* read first character */
while(!feof(inter0) && single_char != '\n')
{
22 word[i] = single_char;
23 printf ("i = %d %c\n", i, word[i]);
i++;
single_char = getc(inter0);
}
27 word[i] = '\0'; /* terminate that word. replace the '\n' with '\0' */

29 printf("word[17] = %c\n", word[17]);
30 printf("word[18] = %c\n", word[18]);

printf("word = %s\n", word);
33 result = strcmp (word, "00:E0:18:06:1C:64");
printf("result = %d\n", result);
printf("\n");
return(word);
}

/*************************/

int main()

{

char word[17] = "12345678901234567";
char word0[17];
char word1[17];
char file_name0[] = "/var/apache/inter0";
char file_name1[] = "/var/apache/inter1";

50 word0 = read_file_nic(file_name0, word);
51 word1 = read_file_nic(file_name1, word);

printf("word0 = %c\n", word0);
printf("word1 = %c\n", word1);
}
 
Old 06-12-2003, 04:17 PM   #2
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
Thumbs up Problem solved.

Never mind. I got it figure out already. This will save your resource for someone else. Thank you for looking at it
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
C can 't return a character array Linh Programming 5 06-18-2003 04:58 AM


All times are GMT -5. The time now is 10:56 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration