LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Cannot pass and return a character array (https://www.linuxquestions.org/questions/programming-9/cannot-pass-and-return-a-character-array-65246/)

Linh 06-12-2003 03:59 PM

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);
}

Linh 06-12-2003 04:17 PM

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


All times are GMT -5. The time now is 05:55 PM.