Thread: Input Problem

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    9

    Question Input Problem

    I need a little help here please. I'm having the user input integers until EOF is indicated.

    So here's my error:

    ------ Build started: Project: Project10, Configuration: Debug Win32 ------
    Compiling...
    project10.c
    Linking...
    project10.obj : error LNK2001: unresolved external symbol _array
    C:\C\Project10\Debug\Project10.exe : fatal error LNK1120: 1 unresolved externals
    Build log was saved at "file://c:\C\Project10\Project10\Debug\BuildLog.htm"
    Project10 - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    Here's my code:
    Code:
    #include <stdio.h>
    
    int size = 0;
    int array[];
    
    void userinput(int *array){
    	int scanf_return = 0;
    	do{
    		printf("\nEnter an integer or EOF to terminate: ");
    		scanf_return = scanf_s("%d", &array[size++]);
    	}
    	while (scanf_return != EOF);
    }
            
    void swap(int *a, int *b){
         int c;
         c=*a;
         *a=*b;
         *b=c;
         }
    
    void usersort(int *array){
         int i;
         for(i=0;i<size-1;i++){
                        if(*(array+i)>*(array+i+1)){
                                    swap(array+i,array+i+1);
                                    i-=2;
                                    }
                        }
         
         }
    
    
    
    int findmin(int *array){
        return array[0];
        }
    
    int findmax(int *array){
        return array[size-1];
        }
    
    
    void printminmax(int min,int max){
         printf("The min is: %d \nThe max is: %d\n", min,max);
         }
    
    void printarray(int *array){
         int i;
         printf("The elements of the sorted array from smallest to largest:\n");
         for(i=0;i<size;i++) {
                             printf("%d\t",array[i]);
                             }
         }
    
    int main(){ 
        
        int min,max;
        userinput(array);
        usersort(array);
        min = findmin(array);
        max = findmax(array);
        printminmax(min,max);
        printarray(array);
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Your "array" doesn't have a size. It must have a size.
    As a side note, remove your global variables and make them local. Just as you pass the array, pass its size as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    9

    Exclamation Edited

    I've set the size to 10 but if I enter "EOF" I get a continuous loop. What else do I need to do to terminate the program?

    Thanks!

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    The string "EOF", when entered at the console, is not the same as the constant EOF that you refer to in your code. EOF is actually a code sent by your OS. You can enter that particular value at the console by pressing Ctrl+D.

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    9
    Thanks! I got it now! Ctrl Z works wonders!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. geting input in C, problem in getting input
    By BujarM in forum C Programming
    Replies: 3
    Last Post: 04-17-2009, 09:38 PM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  4. Problem with File Input & Pointers
    By jenna in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 11:34 PM
  5. Problem with text input
    By newbie in forum C++ Programming
    Replies: 2
    Last Post: 03-10-2002, 04:44 PM