LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   function won ' t return character array word (https://www.linuxquestions.org/questions/programming-9/function-won-t-return-character-array-word-77704/)

Linh 07-31-2003 11:31 AM

function won ' t return character array word
 
function won ' t return character array word

===========================

root:~# ./test-small-network-sh-4

in read_file_nic word = 0001010002020004110009440005050008220007280010480012330010100013090016440013520032200020550019040019
21
1 in main word = <---- word array is empty

===========================
Code:

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

char read_file_nic(word)
  char word[256];
  {
    FILE *interface, *fopen();

    /* process_name_2 is now a file name */
    interface = fopen(process_name_2, "r");
    if (fopen(process_name_2, "r") == NULL)
      {
        perror("Couldn't open file");
        /* shut_down_services(); */
        exit(1);
      }

    fscanf(interface, "%s", word);
    printf("in read_file_nic word = %s\n", word);

    fclose(interface);
    return(word[0]);
  }

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

main()
 {
  char word [256] = "";

  read_file_nic(process_name_2, word);
  printf ("1 in main word = %s\n", word);

 }


Mara 07-31-2003 06:11 PM

Re: function won ' t return character array word
 
Quote:

Originally posted by Linh
Code:

char read_file_nic(word)
  char word[256];


Change it. Give one of 'word's a different name.


All times are GMT -5. The time now is 11:51 AM.