Iam3R 24 Junior Poster

You are right -- Code::Blocks (which also uses MinGW ) doesn't produce warnings or errors on that either. VC++ 2008 Express produces a warning. I'm not familiar enough with gcc to know if there are any flags that will make that compiler produce a warning on it.

there are some flags which enables the missing of case or default or both in an out side of switch and when used with enum as case constant.

these are: gcc filename.c -Wswitch-enum warns whenever a switch statement has an index of enumarated type and lacks a "case" for one or more of the named codes of that enumeration

or simply we can use gcc filename.c -Wall

Ancient Dragon commented: Thanks :) +25
Iam3R 24 Junior Poster

I hope what he wants he is just " find the middle element when you have given three elements"

Ex: 1,3,6 the middle element is 3 ( this we cant get just by dividing)
5,6,7 the the middle element is 6.

if this is the case :

int find_mid(int n1, int n2, int n3)
{
  int mid;
  if( n1 > n2 )   {
          if( n3 > n2)
                {
                        if( n3 < n1 )
                                mid = n3;
                        else
                                mid = n1;
                }
         else {
                mid = n2;
        }
 }
 else {
        if( n2 > n3 )
         {
                if ( n1 > n3)
                  mid = n1;
                else
                mid = n3;
         }
        else{
                mid = n2;
        }
}
return mid ;
}

the driver:

int main()
{
        printf( "%d  ", find_mid(3,4,7) );
        printf( "%d  ", find_mid(5,2,8) );
        printf( "%d  ", find_mid(2,9,4) );
        printf( "%d  ", find_mid(7,5,9) );
        printf( "%d  ", find_mid(7,4,6) );
        printf( "%d  ", find_mid(1,3,6) );
        printf( "%d  ", find_mid(5,6,7) );
return 0;
}
Iam3R 24 Junior Poster

i run the below code and surprised to see the o/p .

take a look and let me know whats happenning there.

#define print(x) printf(#x"=%d\n",x)
int main(){
        int a[10];
        print(a);
        print(*a);
        print(*a+1);
        print(*a+3);
        print(*a+1-*a+3);
        return 0;
}

Out Put:

[Zonnie@telnet CPz]$gcc funny.c
[Zonnie@telnet CPz]$ ./a.out
a=-1073745776
*a=1
*a+1=2
*a+3=4
*a+1-*a+3=4

regardless of whatever stores at a shouldn't it produce -2.

whats the story ?

Iam3R 24 Junior Poster

i hope this is what you want ..

i just edited , but some unneccessary statements/ variable are present that will not harm our prgram.

#include<stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 1000
#define SIZE 100
void search_string(char *file, char *pat);

int main()
{
      int counter = 0;
      int i=0;
     char ch;
     const char filename[] = "in.txt";
     char pat[50];
    FILE *file = fopen(filename, "r");
    if ( file != NULL )
    {
     char line [ MAX ];
     while(isspace(ch=fgetc(file))) ;
     pat[i++] = ch;
     while(!(isspace(ch=fgetc(file))))
     pat[i++] = ch;
     pat[i] = '\0';
     rewind(file);
     while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
     {
            ++counter;
            printf( "%d  ", counter);
            fputs ( line, stdout ); /* write the line */
            search_string(line,pat);
   }
      printf( "\n\n");
      //search_string(line);
      fclose ( file );
   }
   else
   {
      perror ( filename );
   }

   char wait;
   scanf( "%c", &wait );
   return(0);
}
void search_string(char *file, char *pat)
{
        char *ptr, *strptr, word[SIZE] = {" "};
        int i = 0, j = 0;
        int spc =0;
           /*
        while (*ptr != '\0')
        {
                if (isspace(*ptr) && spc == 0)
                                 {
                                    spc  = 0;
                                         }
                if(spc != 0 && isspace(*ptr))
                                                break;
                if(isalnum(*ptr))
                                {
                                    spc =1;
                                    word[i] = *ptr ; // file[i];
        / / here file[i] is blank , is a problem do you really want that
                                   i++;
                        }
                    ptr++;
                 }
              word[i]='\0';
             */

        strptr = file;
        while ((strptr = strstr(strptr, pat)) != NULL)
        {
                strptr++;
                j++;
        }
        printf("%s occured %d times in the string\n", pat, j);
}
Grn Xtrm commented: Thanks for the help. +1