--- charlie_chan <[EMAIL PROTECTED]> wrote:
> uday wrote:
> > Hi Charlie,
> >
> > What is the exact error that you are seeing? I
> dont find any thing wrong with the offending line.
> >
> > Thanks
> > Uday
> >
> > ----- Original Message ----
> > From: charlie_chan <[EMAIL PROTECTED]>
> > To: [email protected]
> > Sent: Saturday, November 25, 2006 9:20:19 PM
> > Subject: [c-prog] Illegal Struction Operation?
> >
> > Why is this part of the follow code sample an
> illegal structure operation?
> > (My intention is to eventually convert the string
> in the structure to a 
> > lower case
> > string that is external to the structure.)
> >
> > struct Indl_dir {
> >     char Lname[30];
> >     char Fname[30];
> >     int areaCode;
> >     char number[9];
> >     struct address addr[MAX];
> > } a_entry[MAX];
> >
> > void findPerson(void)
> > {
> >     register int i, len; // original
> >     int cmp; // original
> >     char strRecv[30]; // original
> >     char strLower[30];
> >     int x=0;
> >
> >     /* Used fgets function for advanced features
> */
> >     printf("Find LAST name: ");
> >     fgets(strRecv,28,stdin);
> > //LINE 259
> >     /* stripping the newline info and replacing it
> with null */
> >     len=strlen(strRecv)-1;
> >     if(strRecv[len]=='\n') strRecv[len]='\0';
> > //LINE 263
> >     for(i=0; i<idx; i++)
> >     {   
> >        // Here is the offending code
> ////////////////////////////////////
> >         for(x=0; a_entry[i]; x++)
> strLower[x]=a_entry[i].Lname[x];
> >         printf("%s\n", strLower);
> >         
> >
>
/////////////////////////////////////////////////////////////////////////////
> >         cmp = strcmp(a_entry[i].Lname, strRecv);
> // original
> >         if(!cmp)
> >         {
> >             printf("%s %s: \(%d\) %s\n",
> a_entry[i].Fname, a_entry[i].Lname,
> >                 a_entry[i].areaCode,
> a_entry[i].number);
> >             printf("%s, %s, %s  %s\n",
> a_entry[i].addr[i].street,
> >                 a_entry[i].addr[i].city,
> a_entry[i].addr[i].state, 
> > a_entry[i].addr[i].zip);
> >         }
> >     }
> > }
> >
> The error message is the same as the subject of the
> message.
> However, I finally made everything work.  Here is
> what I did:
> void findPerson(void)
> {
>     register int i, len; // original
>     int cmp; // original
>     char strRecv[30]; // original
>     char strToLower[30]; // new
>     int x=0;
>     int len2;
> 
>     /* Used fgets function for advanced features */
>     printf("Find LAST name: ");
>     fgets(strRecv,28,stdin);
> //LINE 259
>     /* stripping the newline info and replacing it
> with null */
>     len=strlen(strRecv)-1;
>     if(strRecv[len]=='\n') strRecv[len]='\0';
> //LINE 263
>     for(i=0; i<idx; i++)
>     {
>         // The next seven lines of code are for
> transferring the
>         // data in the structure strings,
> a_entry[i].Lname, to a
>         // string external to the structure.   The
> external string,
>         // strToLower is then converted to lower
> case and a null
>         // escape sequence character is added at the
> end of the
>         // string.
>         len2=strlen(a_entry[i].Lname); // Get the
> length of the struct 
> string
>         for(x=0; x<len2; x++)
>         {
>             strToLower[x]=a_entry[i].Lname[x];
>             strToLower[x]=tolower(strToLower[x]);
You could have done
strToLower[x] =tolower(a_entry[ i].Lname[ x]);
and saved a step.

>         }
>         strToLower[len2]='\0';
> 
You could also use stricmp (not sure if it is standard
or not) which does a case immateriel compare.

Ray
>         cmp = strcmp(strToLower, strRecv); // Now
> compare the two lower 
> case strings
> 
>         if(!cmp)  // If a string in the struct
> compares to the one or 
> more entries, print info
>         {
>             printf("%s %s: \(%d\) %s\n",
> a_entry[i].Fname, a_entry[i].Lname,
>                 a_entry[i].areaCode,
> a_entry[i].number);
>             printf("%s, %s, %s  %s\n",
> a_entry[i].addr[i].street,
>                 a_entry[i].addr[i].city,
> a_entry[i].addr[i].state, 
> a_entry[i].addr[i].zip);
>         }
>     }
> }



 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

Reply via email to