what si wrong with this

This is a discussion on what si wrong with this within the C Programming forums, part of the General Programming Boards category; im so tired of this idun understand wtf can be wrong with it, its just ridiculous Code: int main(int argc, ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    what si wrong with this

    im so tired of this idun understand wtf can be wrong with it, its just ridiculous

    Code:
    int main(int argc, char* argv[])
    {
        
        FILE *fp;
        fp = fopen("input1.txt", "r");
    
        //variable declarations
        int array[500];
        int i = 0;
        char buffer[300];
        char word[300];
          while (fgets(buffer, sizeof(buffer), fp) != NULL)
          {
    	sscanf(buffer, "%s", word);
    	printf("%s\n", word);
    	array[0] = word;        // <---------- error ! why
     	//printf("%i\n", array[i]);
          	i++;
          } //end of file
    }
    //end of main
    i get warning: assignment makes integer from pointer without a cast

    why
    why the hell

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    i canna beleev ur tryin 2 asgn a char * 2 a int! ROFL
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    ok wait
    ignore tht
    look at this

    Code:
    int main(int argc, char* argv[])
    {
        
        FILE *fp;
        fp = fopen("input1.txt", "r");
    
        //variable declarations
        int array[500];
        int i = 0;
        char buffer[300];
          while (fgets(buffer, sizeof(buffer), fp) != NULL)
          {
    	array[i] = buffer;
          	i++;
          } //end of file
    }
    //end of main
    this is wut i had, and again tried to assign int to word; wasted hours for this ........ and its obviously wrong.
    close top

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    Code:
    array[i] = atoi(buffer);
    If you understand what you're doing, you're not learning anything.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    That's because you cannot assign strings with the equals sign in C. Use the strcpy() (or similar) string library function or use fscanf().

    Add to that your array[500] is only 1 string. If you want to store multiple strings you need a 2 dimensioned array ... array[500][100]; or such.

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    Quote Originally Posted by CommonTater View Post
    That's because you cannot assign strings with the equals sign in C. Use the strcpy() (or similar) string library function or use fscanf().

    Add to that your array[500] is only 1 string. If you want to store multiple strings you need a 2 dimensioned array ... array[500][100]; or such.
    Uhh, array is an array of ints. Not a string.
    If you understand what you're doing, you're not learning anything.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by itsme86 View Post
    Uhh, array is an array of ints. Not a string.
    Oops... my mistake, sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 04:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21