🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #304

Re: char array compare

#304
From: Randy Charles Morin
Date: Sat, 26 Jan 2002 02:35
103 lines
2885 bytes
Use STL string class
--
Randy Charles Morin
http://www.kbcafe.com

Feel free to contact me by private email or messenger
morin_randy@hotmail.com
randy@kbcafe.com

#include <iostream>

struct mystr
{
char id[7], name[21];
};

mystr s[50];

void main()
{
  int i, j ;
  char vid[7];

  for (i=0; i<2 ; i++)
  {
   std::cout << "Stud ID : ";
   std::cin >> s[i].id;
   std::cout << "Name    : ";
   std::cin >> s[i].name;
  }

  for (i=0; i<2 ; i++)
  {
   std::cout << "ID: " << s[i].id << "\t" << "Name: " << s[i].name << std::endl;
  }

  std::cout << "\nEnter search id: ";
  std::cin >> vid;

  for (i=0; i<2 ; i++)
  {
   if (std::string(vid) == std::string(s[i].id))
   {
   std::cout << "\nFound id: " << s[i].id;
   }
   else
   {
   std::cout << "\nNot found you id " << vid;
   }
  }
}



"EL" <lameddie@yahoo.com> wrote in message news:a2s339$ngo3@imsp212.netvigator.com...
> Help!
>
> How can i compare a char array from defined structure with input char?
> I can't get the expected result from the following coding. Pls help!
>
>
> struct mystr
> {
> char id[7], name[21];
> };
>
> mystr s[50];
>
> void main()
> {
>   int i, j ;
>   char vid[7];
>
>   for (i=0; i<2 ; i++)
>   {
>    cout << "Stud ID : ";
>    cin >> s[i].id;endl;
>    cout << "Name    : ";
>    cin >> s[i].name;endl;
>   }
>
>   for (i=0; i<2 ; i++)
>   {
>    cout << "ID: " << s[i].id << "\t" << "Name: " << s[i].name << endl;
>   }
>
>   cout << "\nEnter search id: ";
>   cin >> vid;endl;
>
>   for (i=0; i<2 ; i++)
>   {
>    if (vid == s[i].id)
>    {
>    cout << "\nFound id: " << s[i].id;
>    }
>    else
>    {
>    cout << "\nNot found you id " << vid;
>    }
>   }
> }
>
>
Technical Details
Message-ID: <oMo48.1$BF.93@interramp>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!unlisys!news.snafu.de!peerfeed.news.psi.net!filter.news.psi.net!psinr!interramp!not-for-mail
References: <a2s339$ngo3@imsp212.netvigator.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f8d38,70272e41ccb8f8b6
X-Google-Attributes: gidf8d38,public
X-Google-Thread: 114592,70272e41ccb8f8b6
X-Google-Attributes: gid114592,public
X-Google-Thread: 109fba,70272e41ccb8f8b6
X-Google-Attributes: gid109fba,public
X-Google-ArrivalTime: 2002-01-25 18:50:46 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!unlisys!news.snafu.de!peerfeed.news.psi.net!filter.news.psi.net!psinr!interramp!not-for-mail
From: "Randy Charles Morin" <rmorin@kbcafe.com>
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++
References: <a2s339$ngo3@imsp212.netvigator.com>
Subject: Re: char array compare
Lines: 105
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <oMo48.1$BF.93@interramp>
Date: Fri, 25 Jan 2002 21:35:05 -0500
NNTP-Posting-Host: 154.20.73.96
X-Trace: interramp 1012013204 154.20.73.96 (Fri, 25 Jan 2002 21:46:44 EST)
NNTP-Posting-Date: Fri, 25 Jan 2002 21:46:44 EST