cant get output

This is a discussion on cant get output within the C Programming forums, part of the General Programming Boards category; program doesnot hav syntax error but doesnot give its specified output might be some logical error cant find it. Code: ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    10

    cant get output

    program doesnot hav syntax error but doesnot give its specified output might be some logical error cant find it.

    Code:
    /* program to store runtime data in two multidimentional array and match them if same word occurs b/w them 
    it is omitted in second and remaining is printed again */
    
    #include<stdio.h>
    #include<string.h>
    int storear(char s[],int flag);
    void match(char *s1[],char *s2[]);
    int storear(char s[10],int flag)                         /*STORE STRINGS IN ARRAY*/
    {
                 int i;             
                 char c;
                      for(i=0;i<=9 &&(c=getchar())!=' ' && c!='\t' && c!='\n' &&c!=EOF;i++)
                         s[i]=c;
                       if(c=EOF)
                       flag=1;
                       return (int)s;                   /*CAST CONVERT POINTER TO INT*/
    }             
    void match(char *s1[], char *s2[])                      /*MATCH TWO MULTIDIAMENTIONAL ARRAY */    
    {
         char *t,*e;
         int c,i=0,j=0;
         for(i=0;i<=9;i++)
         {
              for(j=0;j<=9;j++)
              {
                   t=s1[i];
                   e=s2[j];
                   c=strcmp(t,e);
                   if(!c)
                   {s2[j]=s2[++j];
                   --j;
                   }
                   }  
    }
    }
    main()
    {
    int j=0,i=0,flag=0;
    char *s3[10],*s4[10],s[10],*d;
    for(i=0;i<=9 ;i++)
    {
    
                 if(flag==0)
    s3[i]=(char *)storear(s,flag);
    else
    s3[i]='\0';
    }
    flag=0;
    for(i=0;i<=9 && (!flag);i++)
    {
                 if(flag==0)
    s4[i]=(char *)storear(s,flag);                              /*CAST FOR INT TO POINTER*/
    else
    s4[i]='\0';
    }
    match(s3,s4);
    while (s3[j]!='\0')
    {d=s4[j++];
    printf("%2s",*d);
    }
    getch();
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code:
    if(c=EOF)
    Equal sign parity error.

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    i changed it to
    Code:
    if(c==EOF)
    ITS NOT WORKING YET

  4. #4
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    58
    for(i=0;i<=9 &&(c=getchar())!=' ' && c!='\t' && c!='\n' &&c!=EOF;i++)
    s[i]=c;
    if(c==EOF)
    flag=1;
    While calling the storear function inside the main function, you are passing the flag value only.
    So the variable flag becomes local in the storear function.

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    so taking it as global variable can work

  6. #6
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,641
    While using a global would work, it's a bad idea. Change the function to take a pointer to an int for the flag argument, then pass the address of the flag argument in main and set the flag like this in the function:
    Code:
    *flag = 1;

  7. #7
    Registered User
    Join Date
    Apr 2010
    Posts
    79
    Also here's a link explaining some of the problems that arise when using global vars.

    Global Variables Are Bad

    It does have a section with exceptions to the rule, but saving keystrokes with global declarations can be quite a .......... if you want to extend the current program later.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ overlapping output and adding extensions to output files
    By lordmorgul in forum Linux Programming
    Replies: 9
    Last Post: 05-11-2010, 08:26 AM
  2. How to edit output in struct and call for the output
    By andrewkho in forum C Programming
    Replies: 4
    Last Post: 03-16-2010, 10:28 PM
  3. terminal output not showing output properly
    By stanlvw in forum C Programming
    Replies: 13
    Last Post: 11-19-2007, 09:46 PM
  4. output a string to a standard output
    By sh4k3 in forum C Programming
    Replies: 3
    Last Post: 06-15-2007, 05:59 AM
  5. Replies: 3
    Last Post: 02-19-2003, 07:34 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