why its not inputting as before..

This is a discussion on why its not inputting as before.. within the C Programming forums, part of the General Programming Boards category; previoslyi constructed this code for entering an integer array in a row. it worked fine. here as it was before: ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    why its not inputting as before..

    previoslyi constructed this code for entering an integer array in a row.
    it worked fine.
    here as it was before:
    Code:
     
    #include <stdio.h>
    int read_array(int input[],int i,int size);
     
    int main()
    {
    	int i;
        int input[40];
        printf("%d\n",read_array(input,0,8));
      for(i=0;i<8;i++)
      {
        printf("%d ",input[i]);
      }
       printf("\n");
    }
    int read_array(int input[],int i,int size)
    {
    	int flag,rt;
           
    	if (i==size)
    	{
         
    	   return 1;
    	}
         flag=scanf("%d",&input[i]);
    	 if (flag==0)
    	 {
    		 return 0;
    	 }
    	 else
    	 {
    	 }
         rt=read_array(input,i+1,size); 
    	 return rt;
    }
    now when i tried to integrate it into the big program
    by basicly doing copy paste (in option 3)
    it just doesnt work like before
    why??
    Code:
    
    #include <stdio.h>
    int read_array(int input[],int i,int size);
    void recSelSort(int array[],int length);
    void selSort(int array[], int i ,int length);
    void swap(int num[],int i,int j);
    int recFindMin(int array[], int index);
    
     void remove_duplicates(char string[], int index);
    void overwrite(char string[], int index);
    int has_duplicate(char string[], int index, char ch);
    
    
    int merge_strings(char str1[], int index1,char str2[],int index2, char result[], int index3);
    void read(char input2[],int i);
    void main_menu();
    void show_menu();
    void clean();
    int merge(char str1[], int index1,char str2[],int index2, char result[], int index3);
    int merge_strings(char str1[], int index1,char str2[],int index2, char result[], int index3);
    
    void main()
    {
         main_menu();
    
    }
    void main_menu()
    {
        //opt1
    	int i;
    	int size;
        char input[255];
        char input2[255];
        char result[510]={0};
        int flag;
       //opt1
    
    
    	char opt[900];
    
       show_menu();
    
       scanf("%s",opt);
    
       clean();
    
       if((opt[0]>='0')&&(opt[0]<='9')&&(opt[1]=='\0'))
       {
           if (opt[0]=='1')
    	   
    	   if (opt[0]=='2')
    	   {
    		
    	      
    	   }
    	   if (opt[0]=='3')
    	   {
    		   printf("Please enter the size of array you want to sort:\n");
    		   scanf("%d",&size);
    		   clean();
    		   printf("Please enter %d values for the array (in one row):\n",size);
    		    read_array(input,0,size);
                                          clean();
    			for(i=0;i<8;i++)
                {
                   printf("%d ",input[i]);
                  }
                 printf("\n");
    			clean();
                
    	   }
    	   if (opt[0]=='4')
    	   {
             printf("4\n");
    	   }
    	   if (opt[0]=='5')
    	   {
             printf("5\n");
    	   }
    	   if (opt[0]=='0')
    	   {
             return;
    	   }
    
       }//end else
       else
       {
           printf("Input incorrect! Please try again.\n");
           printf("\n");
       }
       main_menu();
    }
    void show_menu()
    {
        printf("--------------------------\n");
    	printf("Please enter your choice:\n");
        printf("1) Merge strings.\n");
        printf("2) Remove duplicates in the string.\n");
        printf("3) Sort the array using recursive selection sort.\n");
        printf("4) Calculate the length of the max increasing set.\n");
        printf("5) Check partition.\n");
        printf("0) Exit.\n");
     }
    void clean()
    {
    	int lnd;
        lnd= getchar();
         if (lnd != '\n')
    	 {
             clean();
    	 }
    	 else
    	 {
              return;
    	 }
    }
    
    
    int read_array(int input[],int i,int size)
    {
    	int flag,rt;
           
    	if (i==size)
    	{
         
    	   return 1;
    	}
         flag=scanf("%d",&input[i]);
    	 if (flag==0)
    	 {
    		 return 0;
    	 }
    	 
         rt=read_array(input,i+1,size); 
    	 return rt;
    }
    Last edited by transgalactic2; 01-26-2009 at 02:41 AM.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    it just doesnt work like before
    And how exactly it works now? What is the difference?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User gil_savir's Avatar
    Join Date
    Jan 2009
    Posts
    13
    first fix the following compiler warning (do not ignore those).
    warning C4133: 'function' : incompatible types - from 'char [255]' to 'int *'
    Last edited by gil_savir; 01-26-2009 at 03:02 AM.

  4. #4
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    Quote Originally Posted by gil_savir View Post
    first fix the following compiler warning (do not ignore those).
    i dont get this warning you say on vs2005

    what line is it??

    regarding the out put i get

    here is the printscreen

    http://img231.imageshack.us/img231/2618/14475486gt8.gif


    i cant see why i get this output

    i should get the output as before

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You had input as an int array:

    Code:
       int input[40];
    and now you have it in the bigger program as a char array, but you're using the
    same scanf("%d", &input[i]) on it.

  6. #6
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about mass inputting data
    By Sedia in forum C Programming
    Replies: 3
    Last Post: 10-22-2008, 12:52 PM
  2. strange error in inputting numbers from .txt file
    By angelica in forum C++ Programming
    Replies: 8
    Last Post: 04-10-2008, 11:28 PM
  3. inputting data in a struct
    By raja9911 in forum C Programming
    Replies: 5
    Last Post: 02-02-2006, 03:15 AM
  4. Inputting data from a table of properties
    By cassius in forum C Programming
    Replies: 1
    Last Post: 06-01-2005, 11:22 AM
  5. Inputting text in OpenGL environment
    By Crossbow in forum Game Programming
    Replies: 7
    Last Post: 05-02-2002, 09:31 PM

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