6 Replies - 3981 Views - Last Post: 22 August 2001 - 08:07 AM Rate Topic: -----

#1 EnKRYpTeD  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 128
  • Joined: 11-May 01

Strcmp giving me some problems

Posted 21 August 2001 - 08:19 AM

Ok, i could really use some help im having seriuos problems with some strcmp.  

Heres what i have....

#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
#include <math.h>
#include <string.h>
#include <iomanip.h>
#include <ctype.h>

char sec[13]; char name[21]; char y_n;

void title(); void ask(); void info(); void calculate(char name2, char ss2, float wage2, float hours2); void outputcheck(); void end();

void main() { title(); } void title() { cout<<"Brandon Winkler "; cout<<"C++ Computer "; cout<<"Mr. Hanosh "; cout<<"ECA: Electronic Checking Agent "; ask(); } void ask() { cout<<"Would you like to use the E.C.A. (Elecronic Checking Agent) "; cin>> y_n;

if((strcmp(y_n,"yes")==0)||(strcmp(y_n,"Yes")==0)) info();

else if((strcmp(y_n,"no")==0)||(strcmp(y_n,"No")==0)) end();

else cout<<"Please follow directions "; ask(); }

And when i try and compile it it gives me this error...

D:BrandonECA.cpp(43) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
       Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

Im trying to get it to except yes and no for a program, thats not the whole program but thats the main problem area.... If somone can help me please do ! :) thanks

(Edited by supersloth at 3:40 pm on Aug. 21, 2001)


Is This A Good Question/Topic? 0
  • +

Replies To: Strcmp giving me some problems

#2 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4517
  • View blog
  • Posts: 28,417
  • Joined: 21-March 01

Re: Strcmp giving me some problems

Posted 21 August 2001 - 02:41 PM

i edited it cause at the end of the code thing you put
 you used the wrong slash its 
also i use brackets after every if statement, thats all i could think off.
Was This Post Helpful? 0
  • +
  • -

#3 EnKRYpTeD  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 128
  • Joined: 11-May 01

Re: Strcmp giving me some problems

Posted 21 August 2001 - 02:50 PM

oh thanks bud, but does anyone know?
Was This Post Helpful? 0
  • +
  • -

#4 Null and Void  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 29-April 01

Re: Strcmp giving me some problems

Posted 21 August 2001 - 07:28 PM

Your problem is that you're using a single character to attempt to hold a string (y_n is a character, not a string). If you want to test y_n to see if the entered 'Y' or 'N', do something like this:
cin >> y_n;
if( tolower(y_n) == 'y' ) {
  // Yes
} else {
  // No
}

Or, you could do something like this to handle it a little better:

#include <stdio.h>
#include <ctype.h>

int GetYesNo(void) {  char fc;  scanf("%c%*s",&fc);  return ( tolower(fc) == 'y' ); }


I'm not sure if you can, or how to, do that with C++ i/o, but C works just fine in C++, so no problem.
Was This Post Helpful? 0
  • +
  • -

#5 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4517
  • View blog
  • Posts: 28,417
  • Joined: 21-March 01

Re: Strcmp giving me some problems

Posted 21 August 2001 - 07:38 PM

welcome back null and void, and congrats on the modship.
Was This Post Helpful? 0
  • +
  • -

#6 runtime error  Icon User is offline

  • Lucky.Code
  • member icon

Reputation: 3
  • View blog
  • Posts: 629
  • Joined: 19-March 01

Re: Strcmp giving me some problems

Posted 21 August 2001 - 07:55 PM

what null&void said only you could leave everything the same and just make it [i] char y_n[4]; [i]

(Edited by runtime error at 12:10 am on Aug. 22, 2001)

Was This Post Helpful? 0
  • +
  • -

#7 EnKRYpTeD  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 128
  • Joined: 11-May 01

Re: Strcmp giving me some problems

Posted 22 August 2001 - 08:07 AM

Ooooooohhhhh :) Ok, that makes since now, i forgot i had to set it to 4 :) I havent tested it out yet but im sure it will work, thanks for helping me on that :) i might have figured it out eventually but it might of been to late :)

thanks again

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1