Tuesday, July 14, 2009

Is there a way, in the C language, to compare individual parts of different strings?

I am trying to program just a simple hangman game, and when I wanted to compare the users guess to the string which was the word, I thought this would work...





if (guess==word[i])...





with guess being their input and word[ ] being the string that is the word they are trying to guess. But my compiler had an issue with this, saying that I was passing the getche() function too many arguments. Does anyone know of a proper/better way to compare individual parts of a string to a character? Thanks.

Is there a way, in the C language, to compare individual parts of different strings?
http://www.cppreference.com/stdstring/st...


http://www.die.net/doc/linux/man/man3/st...
Reply:well you can do if(guess[i]==word[i]) ?





example:





%26lt;stdio.h%26gt;


int main() {


char buffer[256];


printf("richest man in the world: _ _ _ _ _ _ _ _ _");


scanf("%s", %26amp;buffer);


char *answer="bill gates";





if(buffer[i]==answer[i]) {


correct execution


i++;


} else {


do w.e


}


}





I dun recommend you use this coding style tho as its messy you will end up with huge code density and it totally kills any way to expand... just wrote this to show an example and didn't even attempt to compile it... good luck.





theres also the strcmp function...





strcmp("test", input);








"But my compiler had an issue with this, saying that I was passing the getche() " %26lt;%26lt;%26lt; this has nothing to do with how your comparing the strings tho ... its complaining about getchar() having too many arguments... read the docs for getchar() an d make sure your calling it correctly.
Reply:You can use the strcmp() function to compare the entire string. However, if you need to compare parts of string, then you must remember that string in C is stored in the form of array of characters. Then you can use the loop as follows:


int streq=1;


for(i=start;i%26lt;end;i++)


{


if(s1[i]!=s2[i])


{


streq=0;


break;


}


}


if(streq) printf("String are equal');


else printf("Strings are not equal");





Remember that st1 and st2 are the two strings and start and end are the starting and ending points of the string.
Reply:of course, but using string compare function which is strcomp





for example





if (strcomp(string1, string2) == 0)


// this means if the two strings are equal





if (strcomp(string1, string2) == 1)


// this means if the two strings are not equal
Reply:its simple just use


scanf("%c",%26amp;guess);


use this statement for accepting a guess character and the program will work thank you and use the same loop and in loop use this statement


if(guess==a[i])


this will work now thank you oh and yeah the string compare function is strcmp and strcmpi where strcmpi is not case sensitive and it is not strcomp


B.C. Rich string help....?

Alright, so as you saw I have a B.C. Rich Bronze Series Warlock guitar (red). I got it a little while ago, and just today one of my strings broke. It was the e (thinnest) string. I need help with getting it replaced. I'm a beginner and this is my first electric guitar. I read online that some some strings break real easily on it, so I need a kind of string that won't =]. Can I do it by myself or should I give it to the store? If I do it myself (which I'll probably get the previous owner of the guitar to do it for me) what kind of strings should I buy? Name, place available, and price please. Thanks a lot guys!!!





P.S. I know this is silly but I have no idea what I'm doing, except for playing, with a guitar. =D

B.C. Rich string help....?
guitar strings are an acquired skill. if you stick with the guitar you will learn. depending on how long the strings have been on the guitar you may just want to replace all six.





I use d'addario (xl) with the high 'e' string (the one you broke) is a .010 gauge. have a friend help you pick them out and show you how to change them. you can do the same at your local guitar shop or general purpose music store.





if you have more break you may want to see if there is something with the frets, saddle, tuning gear or nut that is causing this problem.





good luck!
Reply:Congratulations. I myself have a Beast Platinum Pro.





Be very glad you don't have the floating tremolo. Possibly the hardest thing on earth to string until you know how.





On a B.C. Rich you can't go wrong with GHS Zakk Wylde Boomers. It'll give the guitar that drop tuned sound without having to drop tune it. You'll get a ballsier, heavier sound. Great for power chords.





I can't really help you with where to go since I'm not in your country. Do a bit of homework and find a good guitar store with a good guitar tech.


They should cost around $6-8 for the strings, no idea what setup will cost. Do yourself a huge favour and take the guitar to the store and get them to do a setup. Ask the tech to show you how to string it.





You'll end up with a better sounding guitar and you'll know how to string it right.
Reply:strings are personal preference


i prefer the GHS boomers 10-46


alot of peope like elixers or ernie ball


just gotta play different kinds and find the one you like the best


and changing a string isn't hard


the only way to learn is if you do it yourself
Reply:I used to have a BC Rich Warlock. Mine was Platinum, but I don't think that makes much of a difference. I had a real problem with the hardware, it was a soft hardware (chrome?) that kept on forming burrs in the saddle, which lead to my strings constantly breaking.





I would take your guitar to a guitar tech and ask to have it set up and intonated, and ask them to check for burrs in the saddle. I don't know if your guitar has a tremolo/floating bridge or not, but if it does and you don't know how to use it yet, ask them to block it off - this helps with sustain and helps keep your guitar in tune. Focus on learning how to play your guitar first, then introduce the tremolo when you're a little more comfortable with the basics - and your ear is trained to know when you're going out of tune.





Consider getting replacement hardware or a different guitar. I'm sorry to say it, but I have little respect for BC Rich's less expensive guitars. I got a Jackson, then an LTD, and haven't had a string snap once, versus having strings snap once a month or more with the effing Warlock - I don't even play as much as many other people do, maybe 6-8 hours a week.





Better and thicker strings will help keep you in tune and sound a little better. When you get your guitar set up, ask the tech about bumping up a gauge, if that would be right for you.





Setups can cost anywhere from 30-100 dollars, depending on what you want done. Go to a real music store if you can, go to Guitar Center as a last resort (personal experience hasn't been so good, although a lot will depend on the individual tech doing the work).





Every time you change string gauge you should get your guitar reintonated (or learn how to do it yourself) so your guitar sounds in tune all the way up the neck.








Saul


Could Musharraf be both president and C&C if the CFR and MIC put strings on him like President Bush has???

Counsel on Foreign Relations


Military Industrial Complex

Could Musharraf be both president and C%26amp;C if the CFR and MIC put strings on him like President Bush has???
Bush has cut his string and is on his own god help us

imperial

On my C drive I have folders with long strings of just numbers and letters.?

What information do these folders contain and can I safely delete them?

On my C drive I have folders with long strings of just numbers and letters.?
These are temporary folders Windows creates when doing Windows Updates. Windows puts these on whichever partition on your computer that's the biggest - for most people, usually the C drive. When you reboot after updates, Windows should get rid of these temp folders, but sometimes something will go wrong and it won't delete. It's usually safe to delete these folders, but you might want to set a system restore point beforehand to make sure.
Reply:they sound like temp folders on your drive, if you not sure then just delete to you recycle bin





in a weeks time if your machine is ok, delete
Reply:yep get rid they are old missplaced temp files of a virus eather way get rid





oh and how can deleting a file fry your pc and a real comp dude dosnt use caps lock it is for noobs
Reply:Where exactly are the folders located?





They could be temp files, which you can delete, but could also be something more important.





You might be able to open the files within the folders to have a look.





If in doubt, don't delete them.
Reply:DOOO NOT DELETE THEM YOU CAN FRY YOUR COMPUTER
Reply:That sounds like the temp files you get when doing a windows update, yeah its safe to nuke them from your Hard drive without any problems


Does C++ allow you to declare arrays of strings?

Yes.

Does C++ allow you to declare arrays of strings?
Yes.


In C++ string is array of charecter.


So array of string is indeed 2D array of charecter( or array of charecter type pointer.)
Reply:C++ doesn't have a string object built in.


The Standard Template Library (STL) has a string class and you can declare an array of those.


If you are using Microsoft C++ with MFC, you can declare an array of CString objects.


You also can define your own string class or use and array of arrays of char.
Reply:yes but you need to include a special library. I believe the following would work:





#include %26lt;string%26gt;





string myString [100];
Reply:What you can do is declare a class or a struct of a string, and then declare that class/struct as an array.





E.G.





struct MyStringStructure


{


const char* String;


/*Maybe instead:


char String[256];*/


};





MyStringStructure* g_StringArray;





There are also other ways of doing this, but this seems like the best. I also believe that Microsoft C++ has integrated some sort of string class, but it is very difficult to use from what I understand.


On a guitar how are the strings labeled such as a b c d e f g?

E A D G B E





fattest to thinnest.

On a guitar how are the strings labeled such as a b c d e f g?
e


B


G


D


A


E





Im not sure if this is what you are talking about. But the way I remember it is from a cd called the jimi hendrix experience, it was a cd to learn how to play the guitar. "easter Bunnies Get Down At Easter"
Reply:the thickest one is low e. then going down they are a, d, g, b, e, the other e is a high e.
Reply:depends on the tuning





from thickest to thinest:


standard is EADGBE


drop d is DADGBE


drop c is CGCFAD


and standard b tuning is BEADF#B


there are a lot of ther different tunings as well those are only some.......i usually play in standard or drop d


and my one guitar is set to b tuning
Reply:yeah its such as that





EGBDF
Reply:the normal way is e b g d a E(bottom to top) but you can tune in anyway you want


In c++ how can i read spaces in strings using the >> operator?

example :


the user input is: "firstName lastName"

In c++ how can i read spaces in strings using the %26gt;%26gt; operator?
Setting skipws in your istream will let you do what you want:





string a, b;


cout %26lt;%26lt; "enter two words: ";


cin %26gt;%26gt; skipws %26gt;%26gt; a %26gt;%26gt; b;


cout %26lt;%26lt; a %26lt;%26lt; "," %26lt;%26lt; b %26lt;%26lt; endl;





skipws is set for cin by default, so unless you set noskipws for cin, you could get the same result with:


cin %26gt;%26gt; a %26gt;%26gt; b;





A more general purpose technique is to use getline:





string s;


cout %26lt;%26lt; "enter string: ";


getline(cin,s);


cout %26lt;%26lt; s %26lt;%26lt; endl;





so you get the whole string, with any number of words. Then, of course, you have to do some work to parse it.

elephant ear