Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,339 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,101 people online right now. Registration is fast and FREE... Join Now!




strings and arrays

 
Reply to this topicStart new topic

strings and arrays, trying to compare two strings

rizwans
post 14 Mar, 2008 - 03:56 PM
Post #1


New D.I.C Head

*
Joined: 26 Oct, 2005
Posts: 25


My Contributions


Hi


Allright so here's my problem. I am trying to read in characters from a file and compare two tags. A start tag and an end tag.

The tags consist of <start> and <end> where the start tag and end tags are equal. if they are not equal to each other, then the function must return false.

The function definitions are as follows:
CODE

bool start(ifstream &in, char &curr, char el_name[])
bool end(ifstream &in, char &curr, const char el_name[])

I have to compare the two el_names and see if they are equal.
I tried using strcpy to copy the strings into it's own start tag but that didn't work.
I tried using strcmp and i think it works but i'm not sure where to put it in my code.

I really need help with this. I'm almost done everything but i'm just stuck on this one part.

Thanks
User is offlineProfile CardPM

Go to the top of the page

rizwans
post 14 Mar, 2008 - 04:39 PM
Post #2


New D.I.C Head

*
Joined: 26 Oct, 2005
Posts: 25


My Contributions


ok so i think i figured it but now i've run into another problem
when i try and call the function end(in, curr, el_name)
like so it gives me a compile error saying invalid conversion from const char* to char*
i know this has to do with pointers and such but still not sure how to call it properly
any thoughts?
User is offlineProfile CardPM

Go to the top of the page

KYA
post 14 Mar, 2008 - 09:49 PM
Post #3


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 4,205



Thanked 50 times

Dream Kudos: 1150
My Contributions


It means that you cannot manipulate a const variable. Change the const char it is referring to to a regular one and you should be all set.
User is offlineProfile CardPM

Go to the top of the page

rizwans
post 15 Mar, 2008 - 12:32 PM
Post #4


New D.I.C Head

*
Joined: 26 Oct, 2005
Posts: 25


My Contributions


QUOTE(KYA @ 14 Mar, 2008 - 11:49 PM) *

It means that you cannot manipulate a const variable. Change the const char it is referring to to a regular one and you should be all set.


actually it has to stay there. we have to use the code that the prof gave us and can't manipulate it.
pretty dumb i think
User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 15 Mar, 2008 - 12:39 PM
Post #5


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,027



Thanked 173 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Mind showing us what you have put together so far? So we can see what you are doing and perhaps spot where you need to change things to make it work. Thanks a lot! smile.gif
User is offlineProfile CardPM

Go to the top of the page

rizwans
post 15 Mar, 2008 - 12:40 PM
Post #6


New D.I.C Head

*
Joined: 26 Oct, 2005
Posts: 25


My Contributions


i took out the const and it crashes
User is offlineProfile CardPM

Go to the top of the page

rizwans
post 15 Mar, 2008 - 02:16 PM
Post #7


New D.I.C Head

*
Joined: 26 Oct, 2005
Posts: 25


My Contributions


CODE

bool end(ifstream &in, char &curr, const char el_name[])
{
  bool success = false;
  char ch;

  ch = in.peek();
  in.get(curr);

  if (curr == '<' && ch == '/')
    {
      //      static_cast<el_name *> (el_name);
      name(in, curr, el_name);

      if (success)
        {
          name(in, curr, el_name);
          strcmp(el_name, el_name);
          cout << '>';
        }
    }
  return true;
}

bool name(ifstream &in, char &curr, char el_name[])
{

  in.get(curr);

  if ((curr >= 'a' && curr <= 'z') && (curr >= 'A' && curr <= 'Z'))
    {
      return true;
    }
  else
    return false;

}



Notice that the function parameters for name is just char el_name
whereas the end function takes in const char el_name
not sure how to convert it or if i have to do that.
i can't pass in the function name cause it gives me a compile error
invalid conversion from const char* to char*
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 03:33AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month