Sunday, August 2, 2009

In C++ how do you convert a string to enum?

Lets say I have the code





Code:





enum sKind_t { S_BLUE, S_GREEN, S_YELLOW };








and





Code:





struct square_t { sKind_t kind; string name; };








And Had a file Like this


BLUE apple


GREEN square


GREEN apple


YELLOW Horse





You then write some code to split up the file into two seperrate strings for each line


example





string A= BLUE


string B = apple





how do you store the enum value via a string


so i want say





square_t.kind = A;


but this doesn't work


how do you get strings that are one of the correct values for an enum to work as an enum category?





you change string A to "S_" + A giving S_BLUE

In C++ how do you convert a string to enum?
As the other answerer has said you cannot directly convert from string to enum. What you can do is have a mapping between the strings and the enum. One simple way would be comparing the inputted string with a colour like BLUE, YELLOW, GREEN. If the string is one of these, then use the enum value of it, like S_BLUE, S_YELLOW, S_GREEN.





I do not understand what you are trying to do, but this may help.
Reply:Enum types are named integer constants. You cannot directly convert them to C-style strings, or vice versa.
Reply:I think you need a dictionary. You can use the STL %26lt;map%26gt; class which operates in logarithmic time or for constant time you can use a hash table.


Standard Tuning to Drop C?

My guitar is on standard tuning right now. I really want to play an acoustic song by The Red Jumpsuit Apparatus. The song is in Drop C. Im afraid if i try it on my own i might screw up.





So do you tighten the strings from standard to drop c?


or loosen them?

Standard Tuning to Drop C?
Loosen. It's called DROP c, so you drop the pitch to a lower note.





You're tuning down two full steps too.
Reply:You would loosen them, you might have noticed by now, tightening the strings highers the pitch of the strings, so loosening the strings will lower the pitch of the strings.





http://www.tunemybass.com





That website has preset tunings. In case you don't have a digital tuner. You select your instrument, and then you select the tuning you want to tune your guitar to, and voila, a guitar pops up, and you hover over each string to hear the pitch, and tune your guitar with it. You would select Drop C for your tuning, you'll see it there, it has a whole bunch of other tunings too! It's a great site, I use it all the time. Hope that helps, good luck!
Reply:One of these links will answer your questions.


http://search.yahoo.com/search?p=drop+c+...
Reply:first at all....i know yore trying to play my guardian angel....shitty song....i played it for my former girlfriend......u can get a tuner thats the best way.....but get a chromatic tuner


How do you play a double flat c on the g string on the cello?

A double flat C would be a B-flat. On the G string, that 2nd finger (1st position).


I want to put dots in between some path string. Is there any method for that using Qt and C++ ?

I have requirement for making the text visible in some area.


The text is foler path. But if text increases the space is not available for that. So I want to place dots in between the path string.





ex:


E:\backup\My Share\MATERIAL\vc++books\QtProgramming\e...





I want to show this as


E:\backup\My Share\...\area_earthweb





I am using C++ and Qt. The path is QString or QLabel.





I did manually by caluclating every thing to put dots in between, but I want to know whether is there any other way to do that.

I want to put dots in between some path string. Is there any method for that using Qt and C++ ?
I haven't used the QT API before, but couldn't you use something like the QScrollArea class instead?





That way, they'd be able to see the whole path.


Otherwise, do what you said ... make sure that the text would be visible within the control's boundaries programmatically.

elephant ear

Physics: Stretched strings question?

The figures below show a stretched string vibrating in several of its modes. If the length of the string is 2.0m, what is the wavelength of the wave on the string in (a), (b), (c), (d)?





Picture: http://i25.tinypic.com/2l89mwy.jpg

Physics: Stretched strings question?
a) N O .......... L .............. O N(node)


distance = node to node =λ/2 = L = 2


λ = 4 meter


b) N to N + N to N = λ/2 + λ/2 = 2λ/2


2*λ/2 = 2 %26gt;%26gt; λ = 2 meter


c) 3*λ/2 = 2 %26gt;%26gt; λ = 4/3 = 1.333 meter


c) 4*λ/2 = 2 %26gt;%26gt; λ = 1 meter
Reply:In each step the wave length increases in steps of λ/2.


a ) the length of string = λ/2


b) the length of string = λ/2 + λ/2 = 2 *λ/2


c} the length of string = λ/2 + λ/2 + λ/2 = 3*λ/2


d) the length of string = λ/2 + λ/2+ λ/2 +λ/2


= 4*λ/2
Reply:a)


Two nodes are show and distance between two nodes is λ/2 .


So λ = (2x2) = 4 m





b) λ = 2 m





c) 1.5λ is shown





1.5λ = 2


λ = 4/3 m





d) 2λ = 2


λ = 1 m


Drop c tuning on guitar?

i've seen drop c tuning a few different ways.... i've seen it like this from string 6 to 1....





C F Bb Eb G C





and i've seen it like this from string 6 to 1





C G C F A D





I'm why learn some bullet for my valentine, the tabs said to tune to drop c, but they didnt say what exactly drop c was. i got dethklok tabs and they had it the first way i put. everywhere else i see has it the 2nd way i put it.

Drop c tuning on guitar?
C G C F A D -- Drop-C is the most common, however, many guitarist mess around with tuning to get a different sound. AC/DC-Its a long way to the top, has the standard EADGBE tuned down about 3/4 step....Why? Because they had to have their guitars in tune with the bagpipes!


I need a C language program that prints all the combinations of characters from a string?

example : if the string is ABC, then all the possible combinations of A, B %26amp; C are :


ABC,ACB,BCA,BAC,CAB,CBA

I need a C language program that prints all the combinations of characters from a string?
Here is something I came up with quickly ( not fully complete, I will leave that to you ! )





This quick bit of code will give you a start ( hopefully and no recursion ).





Please note that this is not complete and you will get a memory leak in swap function ( easily fixed btw ! ).





#include "stdafx.h"


#include "stdio.h"


#include "string.h"





void manipulate( char* pString, int index );


char* swap( char* pString, int pos );





char pod[255];








int main(int argc, char* argv[])


{





char* p = "abc";


memcpy( pod, p, strlen( p ) );


for( int i = 0; i %26lt; strlen( p ); i ++ )


{


manipulate( pod, strlen( p ) );


}


return 0;


}








void manipulate( char* pString, int index )


{


int i = 1;


char* p;


p = pString;


while( index %26gt; 1 )


{


p = swap( p, i );


index--;


i++;


memcpy( pod, p, strlen( pString ) );


printf( "%s\n", p );


}


}





char* swap( char* pString, int pos )


{


char* p = new char[ strlen(pString) + 1 ];


memset( p, '\0', strlen( pString ) + 1);


memcpy( p, pString, strlen( pString ) + 1 );


char temp = p[pos];


p[pos] = pString[pos-1];


p[pos-1] = temp;


return p;


}
Reply:do your homework now, kid.... its for you to learn





if you're still desperate, contact me privately... shall be glad to teach you C


Use C programing language to write a function htoi(s), which converts a string of hexadecimal digits to int.?

Use C programing language to write a function htoi(s), which converts a string of hexadecimal digits (including an optimal 0x or 0X) into its equivalent integer value. The allowable digits are 0 through 9, a through f and A through F.

Use C programing language to write a function htoi(s), which converts a string of hexadecimal digits to int.?
/* only small letters are taken care in this program


you can modify it to take care of capital letters too





*/


// Enjoy ...!!!!!!!!!!!!





#include%26lt;stdio.h%26gt;


main()


{


char s[10];


char *p,c;


int i, sum = 0;


printf("enter hexadecimal number start with 0x\n");





scanf("%s",s);


p=s;





printf("\nYou entered : %s\n",p);


while ( *p != '\0' )


{


c = *p;


if(c == '0' %26amp;%26amp; (*(p+1)) == 'x') p=p+2;


c = *p++;


switch (c)


{


case 'a' : i=10; break;


case 'b' : i=11; break;


case 'c' : i=12; break;


case 'd' : i=13; break;


case 'e' : i=14; break;


case 'f' : i=15; break;


default :


i = (int)(c) - (int)('0') ;


}


sum = 16*sum + i;


}


printf("%s = %d\n",s,sum);


}
Reply:i would do it basically the same way u wud do it if it were decimal





firstly, check for the 0x





then find out the length





then start at rightmost, and work ur way to left, like





110 in decimal


0*1 + 1*10 + 1*100 = 110





do same way for hexadecimal except multiply digit by 16 (to convert characters to their equivalent numbers in hexadecimal, ul probly want to look at an ascii table instead of using a bunch of if thens)
Reply:well, start at the end of the string, add the value of the last charector to an accumulating integer variable. then check next to last, multiply it's value by 16, then add it to the accumulating int. then check the next(moving from last to first), multiply it by 256, then add it to the accumulator





the thing to remember is to multiply the value by the next power of 16 for each charector you are adding the value for





let's say you get 0xA8F9


you want 43257





first add 9 to the accumulating var (if it was a letter, it would be 10-15 for a-f





the next char is 'f' f is 15. so multiply 15 by 16^1 or 16. you get 240, add it to the accumulator


249





the next char is 8, so multiply 8 by 16^2 or 256. you get 2048


add it to the accumulator, now at 249


2297





the next char is 'A' it is 10, so multiply 10 by 16^3.


that is 40960 add it to the accumulator


43257





when you se the x charector, or have checked the whole string, then return your value, your done





I just picked the number out of air, this method works for converting all bases, just change the 16 to the base you have. in oct(8 base) take the values by 8^x. for binary, take it 2^x in decimal, scientific notation is written by n.nnn(10^x) showing that this works for 10 base as well.





as for the code, you have to write it. get something compiled, then if it's got bugs, post the code, and you could get some help debuging.
Reply:100 PRINT "Hello World"


200 GOTO 100

lady palm

Use C programing language to write a function htoi(s), which converts a string of hexadecimal digits to int.?

Use C programing language to write a function htoi(s), which converts a string of hexadecimal digits (including an optimal 0x or 0X) into its equivalent integer value. The allowable digits are 0 through 9, a through f and A through F.





Could you please write down the full CODE for this matter! thanks much

Use C programing language to write a function htoi(s), which converts a string of hexadecimal digits to int.?
int ftoi(char[] s)


{


int len = sizeof(s)/sizeof(char);


int value = 0;


int base =1;


int charInt;





for(int i=len-1;i%26gt;=0;i--)


if( s[i]%26gt;='0' %26amp;%26amp; s[i]%26lt;='9')


charInt = s[i]-'0';


else if(s[i]%26gt;='a' %26amp;%26amp; s[i]%26lt;='f')


charInt = s[i]-'a' +10;


else if(s[i]%26gt;='A' %26amp;%26amp; s[i]%26lt;='F')


charInt = s[i]-'A' +10;


else


return -1;





value += base*charInt;


base *= 16;


}


return value;


}


Can strings have multiple values?

in c++... im trying to program 1 string to have multiple values... so i wont have to create a million different strings... can i do that?? if so... how.... if not... are there any other simple ways to accomplish this??....

Can strings have multiple values?
A variable of any basic type -- string, integer, double, etc. -- can hold only one value at a time.





An array can hold multiple values of the same data type.





http://www.cplusplus.com/doc/tutorial/ar...


Is it safe to leave my guitar in drop c?

i want to keep playing in drop c....i switched for standard and drop d to drop c today...will my guitar be "safe" if i just leave the strings loose and in drop c while in its case? it takes forever to tune back to standard...i guess what i mean to ask is whether or not putting the guitar in drop c is as bad as taking off all the strings at once and not putting any back on for a year.

Is it safe to leave my guitar in drop c?
Yes it's safe...One of my guitars is always in C...





I guess I didn't read full. Ya, Drop C has nothing to do with the effects of de-stringing a guitar and leaving them of. The Truss rod is there to counter the tension of the strings and without them, the neck starts to warp. In drop C, they are loose but still have alot of tension and it's fine. However, depending on the guitar, it may drop out of tune with heavy playing when low in C and down to B
Reply:Yes it is safe. My boyfriend does it all the time and it is actually better than changing it each time.





: )
Reply:No it's dangerous... you might die!!!


How to tune to C# on a 4 string bass?

is there anyone who can tell me in an easy way? i just started playing bass and i dont know how to do it

How to tune to C# on a 4 string bass?
im taking that ur tuning ur default E string to C# (the thickest string). Just tune it so it sounds like when the 4th fret on the 2nd thickest string is held and played.

snow of june

Write a prog. in C to create a string of any length n replace SPACE and @ with % followed by their ASCII value

walk the original string, copying characters to a new string, if a


special character is encountered (SPACE or @) instead copy the ASCII value description.





Inefficient but easy to read--%26gt;





char string1[12] = "Hello World";


char string2[36] = ""; /* enough to convert every character! */





for (i=0, j=0; i%26lt;strlen(string1);i++)


{ if (string1[i] == ' ')


strcat(string2, "%20");


else if (string1[i] == '@')


strcat(string2, "%40");


else


strcat(string2, string1+i);


}





(did I remember the ascii values correctly?)


Write a prog. in C to create a string of any length n replace SPACE and @ with % followed by their ASCII value

walk the original string, copying characters to a new string, if a


special character is encountered (SPACE or @) instead copy the ASCII value description.





Inefficient but easy to read--%26gt;





char string1[12] = "Hello World";


char string2[36] = ""; /* enough to convert every character! */





for (i=0, j=0; i%26lt;strlen(string1);i++)


{ if (string1[i] == ' ')


strcat(string2, "%20");


else if (string1[i] == '@')


strcat(string2, "%40");


else


strcat(string2, string1+i);


}





(did I remember the ascii values correctly?)

Write a prog. in C to create a string of any length n replace SPACE and @ with % followed by their ASCII value
I once did this in C++, which is pretty similar to C. I replaced the word "dog" with the word "cat".





char sentence[100] = "I have a fat dog";


int step = 0;





for(step = 0, step %26lt;=100, step ++)


{





if (sentence[step] == 'd' %26amp;%26amp;


sentence[step + 1] == 'o' %26amp;%26amp;


sentence[step + 2] == 'g')


{


sentence[step] = "c";


sentence[step + 1] = "a";


sentence[step + 2] = "t";


}








}


Can somebody give me a quick tutorial on double bass strings?

I'm looking to buy a double bass :]


but I am really clueless as to what types of strings I should buy. What are some well known brands. And what material strings should I purchase? I am going to be mostly plucking and slapping. Any suggestions regarding strings welcome.


Thanks loves,


Bettie C.

Can somebody give me a quick tutorial on double bass strings?
These are some excellent strings:





http://www.thomastik-infeld.com/





or check out more brands here:





http://www.juststrings.com/





Find more info by checking out some of the sites for bassists below:





http://bassmasta.com


http://www.bassdogs.com/


http://www.bassplayer.com/


http://www.bass-guitars-guide.com


http://www.isbworldoffice.com/


http://www.instituteofbass.com/





Kabum


Any one c jordan from G string divas?

Hot and sarah knicks an all star hot nba knicks .com?


10 point best answer be honest describe what they look like?

Any one c jordan from G string divas?
hi, thats an interesting question! lol! 20/F wondering the same thing... holla back
Reply:wasn't Jordan the skinny one, with no boobs, long hair and the tattoo on her inner hip area?... Love that show!
Reply:what the hell are you talking about

sweet pea

In C++, what is the best way for me to read a users string input....?

How can I take a user's first and last name with std::cin and print it back out with only using one variable? I'm new to C++ but have an extensive understanding of Java and general programing. Here is my code:





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





int main() {


string user;





cout %26lt;%26lt; "Please enter your name: ";


cin %26gt;%26gt; user;


cout %26lt;%26lt; "\nWelcome " %26lt;%26lt; user %26lt;%26lt; "!" %26lt;%26lt; endl;





system("pause");


return 0;


}





The problem is that this program only prints the first string entered.

In C++, what is the best way for me to read a users string input....?
The problem is cin terminates the string when it encounters whitespace. So you have to use another method....








#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





int main() {





string user;














cout %26lt;%26lt; "Please enter your name: ";





// this will allow you to input spaces


getline(cin,user);





cout %26lt;%26lt; "\nWelcome " %26lt;%26lt; user %26lt;%26lt; "!" %26lt;%26lt; endl;








system("pause");


return 0;





}
Reply:Cause you only input one string and output the same thing. Concatenate strings.


In java, cause I am forgetting C++ at the moment





String fullName = fName +lName;


System.out.println(fullName);


OR


System.out.println(flName + " " + lName);
Reply:Using this








#include %26lt;iostream%26gt;








using namespace std;





int main() {





char buffer[100]; //buffer size 100





cout %26lt;%26lt; "Please enter your name: ";


cin.getline(buffer,101 ); //terminate input when carriage return hit, can specify the terminate charater in the third argument by default it's \n





string user = buffer;


//might want to do tokenizing here if you have multiple input


cout %26lt;%26lt; "\nWelcome " %26lt;%26lt; user %26lt;%26lt; "!" %26lt;%26lt; endl;





system("pause");


return 0;


}


Write a c Function which converts string to an integer?

prototype of atoi function

Write a c Function which converts string to an integer?
#include %26lt;ctype.h%26gt;





int atoi(char *s)


{ int r=0;


while (isdigit(*s))


{ r = (10*r) + (int)(*s-'0');


s++;


}


return r;


}

bottle palm

In c++, in this statement:[string!='\0']. What is the meaning of '\0'?

I find many explainers, but a very small number of enlighteners. First, think what is a string in C++: it is an array of char-s. How do declare one? You either use





char Name[20] - this declaration truly looks like an array





or use





char * Name - this one does not upfront look like an array, but it is. It does not yet have a size associated with it, so you have got to be more careful with this one. First you would want to allocate a size and then use it.





But in both cases, you have got an array, and you can access any element of that array using the notation Name[index].





So let's start populating Name. Say you want to put "Kim". So:





Name[0] = 'K';


Name[1] = 'i';


Name[2] = 'm';





does that . But there is something in this manner of population which bothers us. What's that? First, if you pass this array to some other function, and it needs to read back the name in it, you will have to also tell it the length! Otherwise how will it know to stop reading at index 2? What will happen if it continues reading beyond index 2? It will get garbage data! Even riskier - what will happen if it continues to read beyond index 19 (assuming that you had used the first declaration to st a size of 20)? It might crash!





So C++ devised a clever way to tell everybody where a string ends. It uses the character '\0' at the end of a string. So, while you populate a string with Kim, you should do:





Name[0] = 'K';


Name[1] = 'i';


Name[2] = 'm';


Name[3] = '\0';





Now if you pass this array to another function, it does not need to know anything else to read back the name in a riskfree way - it just keeps on reading until it gets a '\0'. When it gets the '\0', it stops reading, and treats the value erad so far, excluding the '\0', as the correct value of the string.





So, all it boils down to is that '\0' is a char - a character just like 'K' or 'i' or 'm' or 'x' - just that we have given it a special meaning - it is the "string terminator" in C++. All the string.h functions like strcpy(), strlen(), strcat() etc. operate under the assumption that a string is terminated by an '\0'. For example, if you write the code:





char Name[20];


strcpy( Name, "Kim" );





the function strcpy() will automatically populte Name[3] with '\0'.





There are some other interesting things about '\0'. Every char has an ASCII value. For example, 'A' is 65. 'B' is 66 and so on. What's the ASCII value of a character? Internally, a char is stored in 1 byte (that is not true always, in fact, when it uses 2 bytes, we call that UNICODE, but let us not worry about it now). 1 byte is 8 bits - 8 1's /0's. If you write 8 1-s or 0-s or a mix of 1-s or 0-s side by side, what do you get? A binary number. And if you convert that to a decimal number?You get an integer! So a char can be "read" or "interpreted" as an integer also. That integer is the ascii value of that character. Thus, if you write 65 in binary, the pattern of 1-s and 0-s also represents the character 'A'.





Now that you know what an ASCII value is, let us get back to '\0'. The character '\0' has an ASCII value of 0. Essentially the pattern representing '\0' is





00000000.





Now you can guess why we use that funny \ (slash) in '\0'. Think what would happen if we wrote '0'. Just like 'A' represents the character A and integer 65, what should '0' represent? It should represent the character 0. Character 0 is NOT the same as integer 0. Character 0 in fact, is, the integer 42. Just like 'A' = 65, similarly, '0' = 42, '1' = 43 and so on.





So we cannot use '0' to represent the number 0. So we have to distinguish the chracter representation of 0 somehow from '0'. We do that using a slash.





Phew!

In c++, in this statement:[string!='\0']. What is the meaning of '\0'?
\0 isa string terminator (null character).All strings are terminated by that character.





However, in that test, string would have to be a single character datatype for it to work correctly because thesingle quotes around the \0 equate the value to a character. Comparing astring datatype to a character won't work.


How can I get Borland C++ to output a string to the terminal using 'cout'?

I'm trying to ouput a simple string "hello world" to the terminal. The program compiles and links with no errors, but when I run it there is no output. It's as if the standard output for 'cout' is not the terminal, but I don't know how to change it.

How can I get Borland C++ to output a string to the terminal using 'cout'?
I am not sure what program you tried, but here is one that should work on borlands compiler.





#include %26lt;iostream%26gt;





int main() {





std::cout%26lt;%26lt;"Hello, world!\n";


}





I have included the 'std::' namespace in front of the cout.





%26lt;Edit%26gt;


Are you running the program from the command line, or just clicking on the exe?


If clicking on the exe, a command line will pop up, then disappear after displaying hello world.


You need to run it from the command line.
Reply:#include %26lt;iostream%26gt;


//this could be used instead of


//prefixing each cin/cout with


//std::


using namespace std;





int main()


{


cout%26lt;%26lt;"my String"%26lt;%26lt;endl;


return 0;


}


C++ program that gets another program output from console to a string array.?

Hi all !





Here is my problem...





I'm trying to call a .exe program which I don't have the sources. Only the compiled .exe





I'd like to call it in C but C++ might be used if necessary.





I know that I can use the command :


system("myProgram.exe");


system("pause");


or whatever to execute the program and it works well. However I need to get the output of the program.





For instance if I type system("getmac") I'd like to have the lines in a string array (line by line).





I read about external files to transfer the outputs but this "system call" will occur more than a thousand times / second and I don't want to slow my simulator with HDD files exchanges.





I'm under windows so Unix Pipes (Popen and co...) wouldn't work...





Do you have any clues on how to get this working ? Thx a lot !

C++ program that gets another program output from console to a string array.?
The correct and portable answer is the often forgotten read() and write() from the CSL and CRT. Not only will that work on any hosted compiler on any platform, but using things with such amazingly straightforward names will make you look sexy to the maintenance coders.





You really should read up on their use, first, though (Josuttis' reference on the Standard Template Library goes into excellent detail, since these are used to implement iostreams and other hairy parts of the C++ underbelly.) There's some fairly odd stuff you have to know about the buffering and blocking behavior with all CRT IO stuff in C/C++ if you want it to be portable.





Surprisingly, the clearest and most straightforward examples I'm aware of regarding the use of read() and write() come from a different language entirely - the Erlang manual has a radically simple use of read() and write() when explaining how to open named ports (an Erlang feature.)





You can find the C example here (it's C++ safe too) :





http://www.erlang.org/doc/tutorial/c_por...





If you feel like hooking a brother up over his amazon referral link, hit this to get the aforementioned book: http://sc.tri-bit.com/JosuttisSTL
Reply:You can use pipes in Windows, but the API is a little different. Essentially, this will be doing file I/O but I think you can re-route stdout to your program's stdin.


Can any one tell me from where i can found information about string feature in c++ plz?

http://www.bgsu.edu/departments/compsci/...

Can any one tell me from where i can found information about string feature in c++ plz?
Hi, open this link: http://www.cpp4u.com/


hope u find it usefull...

magnolia

How do I convert a string (with a dollar sign) to a double in C++?

I'm not quite sure how to do this, but I want to convert "$63.50" in a string to "63.50" in a double. How would I go about doing this in C++? Thanks.

How do I convert a string (with a dollar sign) to a double in C++?
given that your variable is named Amt





Amt.erase(1,1);
Reply:first, strip the dollar sign, then convert it to a float.





Personally, I'd say:





double var = atof ( mystring.c_str () + 1 );





That's rather C-ish, but it will work.


Write a program in c++, To print a reverse string of any character,the length of character should not exceed t

program must be in C++.

Write a program in c++, To print a reverse string of any character,the length of character should not exceed t
#include %26lt;string%26gt;


#include %26lt;iostream%26gt;


#include %26lt;algorithm%26gt;


using namespace std;





int main()


{


const string input_string("Can we reverse a string?");





string s(input_string.begin(), input_string.end());





// iterate through all of the characters


string::iterator pos;


for (pos = s.begin(); pos != s.end(); ++pos) {


cout %26lt;%26lt; *pos;


}


cout %26lt;%26lt; endl;








reverse (s.begin(), s.end());


cout %26lt;%26lt; "reverse: " %26lt;%26lt; s %26lt;%26lt; endl;





}
Reply:Can you plz elaborate ur question...


C++ help with character arrays?

I am supposed to compare two strings and write out a message that says"they are the same or the 1st string is greater. the first c-strign I can use the %26lt;%26lt;operator, but on the 2nd I have to use for loop. I worte the program,but it doesn't work correctly. Even if I enter a larger string than the 1st string it gives me that the first is larger than the second. I am also to declare an array w/20 char and initialize it w/ a string constant. then declare a 2nd array of 20 char. this is what I have.


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cstring%26gt;


using namespace std;


int main ()


{


char a[21]= "Have a nice day!";


char cstring[21];


cout%26lt;%26lt;"Please enter a word: ";


cin.getline (cstring,21);


if (strcmp (a,cstring)%26gt;0)


{


cout%26lt;%26lt;"The first string is greater than the other.\n";


cout%26lt;%26lt;a%26lt;%26lt;" is greater than: "%26lt;%26lt;cstring%26lt;%26lt;endl;


}


for (int index=0; index%26lt;21;index++)


{


cout%26lt;%26lt;cstring[index]%26lt;%26lt;endl;








}








return 0;


}

C++ help with character arrays?
i am not an expert C++ programmer but from what I know, while using strcmp you must type the exact same string in as before but with a different number of charectors. From you assignment it sound like you need to compare any two strings. I would then use strlen instead. Heres a good example i made:





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cstring%26gt;


using namespace std;


int main(int argc, char *argv[])


{





char cstring1[21];


char cstring2[21];





cout %26lt;%26lt; "This Program Compares 2 Strings and Tells Which is Greater in length\n";


cout %26lt;%26lt; " 1st Phrase: ";


cin.getline (cstring1,21); //Recieves input for string one


cout %26lt;%26lt; " 2nd Phrase: ";


cin.getline (cstring2,21); //Recieves input for string 2





if (strlen(cstring1) %26gt; strlen(cstring2)) //is string one larger?


{


cout %26lt;%26lt; cstring1 %26lt;%26lt; " is Greater in Length than the Sting " %26lt;%26lt; cstring2;


}else if(strlen(cstring1) == strlen(cstring2)){ //are the strings equal?


cout %26lt;%26lt; "The phrases are equal!";


}else{ //if all other fails do this!


cout %26lt;%26lt; cstring2 %26lt;%26lt; " is Greater in Length than the Sting " %26lt;%26lt; cstring1;


}


cout %26lt;%26lt; "\n\nPhrase 1\tPhrase 2\n";


for (int index=0; index%26lt;21;index++)


{


cout %26lt;%26lt; " " %26lt;%26lt; cstring1[index] %26lt;%26lt; "\t\t " %26lt;%26lt; cstring2[index] %26lt;%26lt; endl;


}


return 0;


}


------------------------Outputs-------...


This Program Compares 2 Strings and Tells Which is Greater in length


1st Phrase: string 1


2nd Phrase: string 22





string 22 is Greater in Length than the String string 1





String 1 String 2


s s


t t


r r


i i


n n


g g





1 2


2





Hope this helps ya!
Reply:When strcmp return 1 or -1 it does not say something bout the length!





Strcmp compares the characters from left to right. When a character is different (see ascii table) then the other one, it will stop processing. It returns 1 or -1 depending on the differences in ASCII value of the characters.





See the ascii table :http://www.asciitable.com/ for values of characters.
Reply:same string return 0;


larger string return -1;


shorter string return 1;


I can not see anything wrong, check my output.


----------------


int main(int argc, char *argv[])


{





char a[21]= "Have a nice day!";


char cstring[21];


cout%26lt;%26lt;"Please enter a word: ";


cin.getline (cstring,21);





cout %26lt;%26lt; "strcmp()=" %26lt;%26lt; strcmp (a,cstring) %26lt;%26lt; "\n";





if (strcmp (a,cstring)%26gt;0)


{


cout%26lt;%26lt;"The first string is greater than the other.\n";


cout%26lt;%26lt;a%26lt;%26lt;" is greater than: "%26lt;%26lt;cstring%26lt;%26lt;endl;


}





for (int index=0; index%26lt;21;index++)


{


cout%26lt;%26lt;cstring[index]%26lt;%26lt;endl;


}





return 0;


}





------------


Please enter a word: Have a nice day!


strcmp()=0


H


a


v


e





a





n


i


c


e





d


a


y


!


-----------------------


Please enter a word: Have a nice day!Have a nice day!


strcmp()=-1


H


a


v


e





a





n


i


c


e





d


a


y


!


H


a


v


e


------------------------


Please enter a word: Have a nice d


strcmp()=1


The first string is greater than the other.


Have a nice day! is greater than: Have a nice d


H


a


v


e





a





n


i


c


e





d


A program in C that uses the string command 'strcmp'?

Please provide me a sample program that implements the string function 'strcmp'. I really need this program. Thank you.

A program in C that uses the string command 'strcmp'?
strcmp() is a function that compare the two string. If both string are same then it return 0 else -1.





The program is as follows:





#include%26lt;stdio.h%26gt;


#include%26lt;string.h%26gt;


int main()


{


char str1[10] = "XYZ";


char str2[10] = "XYZ";


if(strcmp(str1,str2)==0)


{


printf("The string are same\n");


}


else


{


printf("Not equal\n");


}


return 0;


}





output:


The string are same
Reply:Can it help u put


http://www.koders.com/c/fid12C8C85975AEE...

forsythia

In C, how can I convert from a non-utf8 character string containing Chinese charcters into utf8?

I have a string of data that usually is 7-bit ASCII (latin-US) but occassionally contains characters with the high-bit set for multibyte Chinese (standard) characters. It could actually be any language but it is most commonly Chinese. I need to put this data into a database that uses utf8 natively. I am programming in C++. Would you use iconv to convert this to utf8? Or would you roll your own code? What is the most likely encoding I'm dealing with here?

In C, how can I convert from a non-utf8 character string containing Chinese charcters into utf8?
I would "roll my own code" out of lack of knowing a better way. It is a matter of adding a constant value to the ascii value and expanding the datatype size which seems simple enough to implement yourself. Good luck!


In the Java method header "public double foo(int i, String s, char c)"....?

what is the return type, method name, and method parameters?

In the Java method header "public double foo(int i, String s, char c)"....?
Return type: double


Method name: foo


Parameters: int i, String s, char c


I want to set all bit of my byte in string... its in c++ language?

Hi :)


i want to initialize all nibble of my byte to f ,for example i have char[10] and i want to initialize it in all byte with ff (0xff)


its mean a=0xffffffffffffffffffff , how could i do it?


thanks friends:)

I want to set all bit of my byte in string... its in c++ language?
You can initialize it when you declare it:


char a[10] = {0xFF, 0xFF, 0xFF,.....,0xFF}





or you can loop through it:


for (int i=0; i %26lt; 10; i++)


a[x] = 0xFF;
Reply:simply And (%26amp;) with char(255)
Reply:Exactly as you showed above.
Reply:u already did.


How do I transfer an array table to a function as a parameter in the syntax programming of C++?

I just solve informatic problems in c++. I have a string array of data which I want to make some comparing with a temp string array so it can move on. That's easy. I use loops and ifs. But the problem is that I use it many times and I want to organize my program. Therefore, i intend to pass the string array of data as a parameter in a particular function. In fact, I would really be appreciated if I can transfer a parameter data type of a string array by reference. Anyways a lot of help would be appreciated.

How do I transfer an array table to a function as a parameter in the syntax programming of C++?
char strArray[][6] = {"AAAAA", "BBBBB", "CCCCC", "DDDDD", "EEEEE"};





int stringCount = sizeof(strArray)/sizeof("AAAAA");





int TestStringArray(char A[][6], char B[])


{


for(int i = 0; i %26lt; stringCount; i++)


{


if(0 == strcmp(A[i], B))


{


return i;


}


}


return -1;








}








void main()


{


char B[] = "EEEEE";





int result = TestStringArray(strArray, B);


}

jasmine

C++ array to hold full name (first last) as a single string in array?

I need to store the full name, first and last name in an array as a single string, and its corresponding value in a parallel array. This means to store the full name in one location in the array. Using C++ and my compiler is Dev C++. I need help with this array primarily how to store the name as one unit and the value in a corresponding location in a parallel array. Here is my code so far:





#include%26lt;iostream%26gt;


#include%26lt;string%26gt;


#include%26lt;cstring%26gt;


#include%26lt;iomanip%26gt;


#include%26lt;fstream%26gt;





using namespace std;








int main()





{





ifstream inFile;





char array1 [10] [50];


char array2 [10] [5];





inFile.open("celebs.txt");





int location = 0 ;





inFile %26gt;%26gt; array1[ location ] %26gt;%26gt; array2[ location ] ;





while ( inFile %26amp;%26amp; location %26lt; 50 )


{


location++;


inFile %26gt;%26gt; array1[ location ] %26gt;%26gt; array2[ location ] ;





}





this is the input file:





Donald Trump 5.1


Paris Hilton 2.98


Lindsey Lohan 3.65


Marion Jones 1.03


Paul McCartney 3.75


Snoop Dogg 1.65


Britney Spears 2.14


Sean Combs 1.07


Heather Mills 2.31


Michael Vick 4.67

C++ array to hold full name (first last) as a single string in array?
Since this is C++, you can take advantage of string methods. I recommend that you scan backward in your input for the last separating space and split the input at that point. Also, instead of two-dimensional char arrays, why not use array of strings? See below for my attempt:





#include%26lt;iostream%26gt;


#include%26lt;string%26gt;


#include%26lt;cstring%26gt;


#include%26lt;iomanip%26gt;


#include%26lt;fstream%26gt;





using namespace std;





const int TotalRows = 10;





int main()





{





ifstream inFile;





string input_string, array1[TotalRows], array2[TotalRows];





inFile.open("celebs.txt");





int location = 0, linecount = 0 ;





while ( linecount %26lt; TotalRows )


{


getline(inFile, input_string);


location = input_string.rfind(" ");


array1[linecount] = str.substr(0, location);


array2[linecount] = str.substr(location+1);


linecount++;


}


inFile.close();





}


What is the code for finding number of charecter present in the string using function in C?

In C.


Using function.

What is the code for finding number of charecter present in the string using function in C?
use strlen() function..


for example:





#include%26lt;stdio.h%26gt;


#include%26lt;string.h%26gt;


main()


{


char str[100];


printf("Enter A String:");


scanf("%s",str);


printf("Length Of Str=%d",strlen(str));


}
Reply:strlen("SomeString")





you need to declare string.h header


Program in C?

How to write a program in C, to accept a string and find the count of lower case and upper case characters?

Program in C?
u can use isupper and islower functions....
Reply:The code is pretty straightforward...should only take about 2 mins to write but i figure from yuor question you just need to know what to be doing rather than the actual solution so here is a point-by-poitn for ya in what you will need to do:





1. Accept input using scanf(..) for string


2. use a for statement to iterate through each character of that string looking at each character..


3. If the character is between a to z then it is lower...if it is between "A" to "Z" it is upper....you can use those actually letters instead of the ascii number rep.


4. for each lower you incremeent the variable countLower++ ... for each upper you incrememnt the variable countUpper++ (these variables are the ones you create)


C++, Binary Searching a string?

Could someone please tell me what is wrong wit this? I basically want to be able to preform a binary search on a string but I'm not quite sure how to do it. If you could please show me how to do it that would be great. The code can be found at http://cpp.sourceforge.net/?show=35467





I have posted it up so it doesn't need to be downloaded or anything.

C++, Binary Searching a string?
C-style strings cannot be compared using == or %26gt; or %26lt; operators, you need to use the strcmp function. Here is a fix to your search function:


Code:





int binarySearch( char array[][SIZE], int numelems, char value[SIZE]) { int first = 0, last = numelems - 1, middle, position = -1; bool found = false; while (!found %26amp;%26amp; first %26lt;= last) { middle = (first + last) / 2; if (!strcmp(array[middle], value)) { found = true; position = middle; } else if (strcmp(array[middle], value)%26gt;0) last = middle - 1; else first = middle + 1; } return position; }





If you used std::string instead of C-style strings, those operators would have had worked well. std::string has those operators overloaded to work as you expect.
Reply:Nice work. You're abusing SF resources for your own webspace. I was wondering about that project, and it turns out you're the admin. Nice...

crab apple

Can someone help with this C++ function?

Given the array declaration:





string DayNames[7] = {"Sunday","Monday","Tuesday","Wednesday"...





Write a C++ function void TellDay (string Week[], int DayNum) , so Friday will be displayed when call it with the statement:


TellDay(DayNames,5);





and Sunday will be displayed when the calling statement is:


TellDay(DayNames,7)

Can someone help with this C++ function?
#include %26lt;iostream.h%26gt;





int daynum, x;


string daynames[7] = {"Monday","Tuesday","Wednesday","Thursda... "Friday", "Saturday", "Sunday"};





void TellDay ()


{


x=daynum-1;


cout%26lt;%26lt;daynames[x];


}





void main()


{


cout%26lt;%26lt;"Enter day number";


cin%26gt;%26gt;daynum;


TellDay();


}


it works i tried it..


Write a c programe to print a string without using semi colon in any of the statements.?

u should use only c or c++ progrmming language and should not use semi colon anywhere not even to terminate stament.

Write a c programe to print a string without using semi colon in any of the statements.?
%26lt;pre%26gt;


#include %26lt;stdio.h%26gt;


int main(int argc, char **argv) {


while( putchar( argv[1][(argc++)-2] )) {


}


}


%26lt;/pre%26gt;


Usage:





gcc -o print print.c


./print "Hello World."
Reply:I learned a bit of c++ and c and you can't do it without semicolons


int main{


st::cout %26gt;%26gt; 'Hello world' ;


};


you need semicolons!!!
Reply:You really need to do your own homework. You'll never learn otherwise.


C++ a loop with string.erase !?

I want to get rid of all numbers in my sentence. This only gets rid of hte first number. What am I doing wrong in the loop?








#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;cctype%26gt;


using namespace std;





int main()


{


string myString="I have 24 bananas.";


size_t len = myString.length();





size_t i=0;


while (i%26lt;len)


{


if ( isdigit(myString[i]) )


(myString.erase(i,1));


++i;


}


cout %26lt;%26lt; myString%26lt;%26lt; endl;


return 0;


}

C++ a loop with string.erase !?
The other answers are generally on mark but the bottom line is that this is not the best erase() method to use in that kind of loop.





myString.erase(i, 1) actually returns a new string reference. You are ignoring the return value but the underlying string has still changed. You have to be careful with stl containers (which include std::string) that the container and its iterators aren't invalidated with operations that mutate the state.





I think the single iterator form of string::erase() is a better choice for what you are doing. Something like:





string::iterator it = myString.begin();





while (it != myString.end())


{


if (isdigit(*it))


it = myString.erase(it);


else


it++;


}
Reply:The 2 and 4 are beside each other. When you erase the letter, all letters after that are shifted back a space. You're saying ++i so it skips one. It's a bit dificult to explain but you'll see it happen if you use:


cout %26lt;%26lt; myString[i];





Basically, fix it by saying:


if ( isdigit(myString[i]) )


{


(myString.erase(i,1));


i -= 2;


}


++i;








I think you might get away with simply --i but I'm not sure. Hope that helps :)
Reply:I have updated the code to properly erase all digits





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;cctype%26gt;


using namespace std;





int main()


{


string myString="I have 24 bananas.";


size_t len = myString.length();





size_t i=0;


while (i%26lt;len)


{


if ( isdigit(myString[i]) )


(myString.erase(i,1)); // erase one character, leave 'i' alone.


else //* This is what I added *//


++i; // advance to next character


}


cout %26lt;%26lt; myString%26lt;%26lt; endl;


return 0;


}


Only One program using all the string function in C Program?

Which function are you keenly looking for? If you have to use any string function in C language, you need to include the String.h header file as #include%26lt;string.h%26gt;. string.h has all the list of string functions such as strlen(), strcpy() etc. Use help function in the C editor to know the list of string functions and their usage.

strawberry

How do I replace an exact string in XEmacs?? (C++ Programming)?

Let's say for example I wanted to replace "apple" with "orange" but I didn't want it to replace the apple in "applesauce" what command will I have to type in the replace buffer?

How do I replace an exact string in XEmacs?? (C++ Programming)?
http://www.xemacs.org/Documentation/beta...


Beginner C++ Help?

Hi,I'm new to C++. And I mean literally new, as in I just started yesterday. I've read a few tutorials and learned somethings but I still know basically nothing. I'm making some simple programs to practice and the current one is a random number generator. Here is the code.





#include %26lt;iostream%26gt;





using namespace std;





int main()





{





int a,b,c,d,e,f;





string g,h="a";





loop:





a = (rand()%10);





b = (rand()%10);





c = (rand()%10);





d = (rand()%10);





e = (rand()%10);





f = (rand()%10);





cout%26lt;%26lt;"\n";





cout %26lt;%26lt; a;





cout %26lt;%26lt; b;





cout %26lt;%26lt; c;





cout %26lt;%26lt; d;





cout %26lt;%26lt; e;





cout %26lt;%26lt; f;





cout%26lt;%26lt;"\n";





cout%26lt;%26lt;"\n";





cout%26lt;%26lt;"To create a new random number, press a and then enter.";





getline (cin,g);





if (g==h){





goto loop;





}





cin.get();





}

Beginner C++ Help?
As Ahmad said, you need to seed the PRNG. srand with time as an argument works well. But I have a few things to say about your code.





The first is your variable names. Please choose more meaningful variable names. You realize they can be more than one letter long right?





Do not use goto and labels. They have their use, but no beginner and most intermediates will encounter such a situation. There are flow control constructs, like for loops, while loops, and do while loops. Use them. Your code could be rewritten to use a do-while loop and two for loops.





There’s something called an array. You should learn it as soon as possible.
Reply:You need to seed the random number generator.





http://www.cprogramming.com/tutorial/ran...


How to write reverse a string program in C ?

/*without using standard functions*/





#include%26lt;stdio.h%26gt;





#include%26lt;string.h%26gt;





#include %26lt;conio.h%26gt;





main()





{





char s[40],c,r[40];





int i,j,p;





clrscr();





printf("Enter the string:");





gets(s);





for(i=0;s[i]!='';i++);





j=i;





printf("The original string is:%s",s);





printf("nThe reverse string is:");





for(p=j-1,i=0;p%26gt;=0;p--,i++)





r[i]=s[p];





r[i]='';





printf("The reverse string is:%s",r);





getch();





}

How to write reverse a string program in C ?
u have a predefined function in string.h library function.


the function is strrev(*char)
Reply:#include %26lt;stdio.h%26gt;


#include %26lt;string.h%26gt;





int main(void)


{


char str1[] = "Pointers are fun and hard to use";


char str2[80], *p1, *p2;





/* make p point to end of str1 */


p1 = str1 + strlen(str1) - 1;





p2 = str2;





while(p1 %26gt;= str1)


*p2++ = *p1--;





/* null terminate str2 */


*p2 = '\0';





printf("%s %s", str1, str2);





return 0;


}
Reply:Check this out


http://discuss.fogcreek.com/techintervie...


http://en.allexperts.com/q/C-1587/C-prog...





both of them are working.
Reply:i think you should use string constant " ' " symbole





OMAR QURESHI


momarqureshi@yahoo.com
Reply:void main()


{


char string1[ ]="this string needs to be revresed";


char string2[35];





/* now calculate length of the string. You can also use strlen() function if allowed */


int i,len;


for(len=0;string1[len]!=NULL;len++);





for(i=0;string1[i]!=NULL;i++)


string2[i]=string1[len-i-1];


string1[len]=NULL; /*terminate the reversed string*/





printf("The reversed string is:\n%s",string2);





}


How to convert from a QTString type to String type in C++ .......... please help me?

i have a file name stored in a varible of type qtstring and i need to move it into a variable of type string.... but i don't know how .... can you help me pleeeeeeeeeeeez.

How to convert from a QTString type to String type in C++ .......... please help me?
#include %26lt;QString%26gt;


#include %26lt;string%26gt;


using namespace std;





const std::string %26amp; qt2string(


std::string %26amp; dest, const qtstring %26amp; src )


{


dest = (const char*) src.data();


return dest;


}

kudzu

How do you convert string into float c++?

If I have a character array:





char a[]={"92*43-2*2/+"};





How would I convert each number in this array to a float?





I've attempted different methods but I end up getting the decimal value for the ascii character.





For example converting 0 to a float I end up with 48.

How do you convert string into float c++?
You would have to write a function to parse the string into its numbers and operators.





Then you would have to write code to apply the operators to the numbers, making sure to use the proper prescendence.





I have no idea how to interpret that "/+" at the end of the string.
Reply:That isn't converting a string to float, it is processing a command string of calculator commands, which is much more.


This would be a string that could be converted to float by skipping the first character "$12345.65"


I need to give a Finite Automata the following language over the alpahabet 0 & 1: all strings ending in 00?

Its this homework I'm stuck on about Automata Theory. I have to give a finite automata to accept the following language over the alphabet {0,1}:


a) the ste of all strings ending in 00


b) the set of all strings with three consecutive 0's


c)the set of all strings with 011 as sub-strings





All I want to know is how to start constructing the diagram and the table! Please, anyone! I need your help! please!!!!

I need to give a Finite Automata the following language over the alpahabet 0 %26amp; 1: all strings ending in 00?
May be you can search at homework help website like http://homeworkhelp.co.in/ .


How do I access non-static variable which is declared globally in the static context using C#?

I want to use globally declared non - static variable in the static context "static void main(String[ ] args )" using C#.

How do I access non-static variable which is declared globally in the static context using C#?
You...cannot. Either declare it as a static variable, or create an instance of the object it is in.


How to use string function in C?

There is no string function you have to use character arrays.





RJ

How to use string function in C?
This depends on what you are trying to do.


You must include strng.h at the top of your file e.g.


#include %26lt;string.h%26gt;





A string is a null terminated char array e.g.


char mystr[80] = "Hello World";


/* mystr is = "Hello World\0" */


mystr[5] = '\0'; /* Null terminated so the string is now Hello*/





Look here http://www.opengroup.org/onlinepubs/0079... for explanations of the functions but basicall you use them like:-





#include %26lt;string.h%26gt;





void main(void) {


char str1[80] = "A String";


char str2[80] = "Another String";





if (strcmp(str1, str2) == 0)


printf ("They are the same\n");


else


printf ("They are different\n");





if (strncmp(str1, str2, 1) == 0)


printf ("The first character is the same\n");


else


printf ("The first character is different\n");





}
Reply:There is no string datatype in C, but there are several functions that work with "strings" (arrays of characters with a null terminator). For example, strcmp, strncmp, strcpy, etc.





Are you referring to these?

garland flower

Op. 131 String Quartet in C# Minor by Beethoven?

Movement IV, It's the one in Band of Brothers





does anyone know a way i could get this a brass quartet?

Op. 131 String Quartet in C# Minor by Beethoven?
see if there's any copies you can buy on the internet, or get the string quartet sheet music and transpose and orchestrate it for a brass quartet.


Friday, July 31, 2009

Op. 131 String Quartet in C# Minor by Beethoven?

Movement IV, It's the one in Band of Brothers





does anyone know a way i could get this a brass quartet?

Op. 131 String Quartet in C# Minor by Beethoven?
Due to the significant differences in the ranges of a trumpet and a violin, it would be difficult to pull this off. You can download a copy of the score, as it's public domain, from the link below and see for yourself.





However, if you really want to do this piece, I am a professional arranger and can see if I could create a workable version for you if you're interested. You would probably need at least one of your trumpet players to be good with a piccolo trumpet to make it most effective.


Reading text files in C++?

How can you read text and integers from a file in C++ and store them as strings and varibles for use in the program. The text file formated like string, string, string, int, int, int, int over serveral lines like below.





Word1 Word2 Word3 Int Int Int


Word1 Word2 Word3 Int Int Int





and so on...

Reading text files in C++?
fscanf()? http://www.cplusplus.com/reference/clibr...


Which is the best string searching algorithm in C# 2003?

the best algorithm which can be implemented in c# 2003 (.net framework 1.1.4322)?

Which is the best string searching algorithm in C# 2003?
palindrom like

blazing star

C++ help? (ten points to person with most answers)?

Is there a function in C++ to enter a string into a zip password and check if that string is the correct password?


Second, how can you:


get part of a string


change a string to uppercase


change a string lowercase





Thanks.

C++ help? (ten points to person with most answers)?
There exists no such function.


To get part of a string, you use the substr member function. Hence,


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


using namespace std;


int main()


{


string s = "Hello World!";


cout %26lt;%26lt; s.substr(3,5) %26lt;%26lt; endl;


return 0;


}


will print out five characters of string s, starting from the character at position 3. The outputted string will be "lo Wo".


To change a string to uppercase: loop through the string and consider each character in turn. If it is greater than or equal to 'a' and less than or equal to 'z', subtract 32 from its ASCII value.


To change a string to lowercase: loop through the string and once again consider each character in turn. If it is greater than or equal to 'A' and less than or equal to 'Z', add 32 to its ASCII value. Hence,


void convert_to_uppercase(string%26amp; s)


{


int i;


for (i=0; i%26lt;s.length(); i++)


if (s[i]%26gt;='a' %26amp;%26amp; s[i]%26lt;='z')


s[i]-=32;


}


void convert_to_lowercase(string%26amp; s)


{


int i;


for (i=0; i%26lt;s.length(); i++)


if (s[i]%26gt;='A' %26amp;%26amp; s[i]%26lt;='Z')


s[i]+=32;


}
Reply:No, there is no function in standard C++ to enter a string into a zip password and check if it is correct. You will have to use a C++ Zip library. I suggest you check out http://www.example-code.com/vcpp/zip.asp


You should be able to convert the MFC examples to C++ with no modification.





Idk about your second question.





Third is:


for(int i = 0;i%26lt;strlen(StringHere);i++)


{


if(StringHere[i] %26lt; 97){StringHere[i] =


StringHere[i]+32;


}


}


Last Question:





for(int i = 0;i%26lt;strlen(StringHere);i++)


{


if(StringHere[i] %26gt;= 97){StringHere[i] =


StringHere[i]-32;


}


}





That function is made from the fact that the lowercase versions of letters in ASCII are always the number of the uppercase + 32. You should be able to put the loops I just posted in a function, so you don't have to write all that everytime you wish to convert to lowercase or uppercase.





http://www.asciitable.com/


C++ Programing Help!, usinng 'string' function to create 'ofstream' file name!?

im doing a program for my class. i have to make a 'string' function that takes the name of the ifstream file (data1.txt) and the string function changes that string into 'data1.csv'.





that way, when i go to open my ofstream file (which doesnt exist, so it'll create it), i use the call of the string function so it creates the file 'data1.csv'


....


here is what my function looks like...


string newoutput (string filename)


{


string newfilename;


int p;


filename.find('.');


p=filename.find('.');


cout %26lt;%26lt; filename.substr(0,p) %26lt;%26lt; ".csv";


return newfilename;


}





...then when i go to open the ofstream file, i have it saying...





result.open (newfilename);





....





but it does not compile. i think it has something to do with the way my function is set up. idk if its outputing it right or not. if i change "result.open (newfilename);" to "result.open ("data1.csv");" then it works exactly how it want it to. but my teacher wants me to use the string function. can anyone help me?

C++ Programing Help!, usinng 'string' function to create 'ofstream' file name!?
Your function actually returns the empty string because note that you have not assinged anything to "newfilename" within that function. Also, have you declared "newfilename" before you used it in the following line of code:





result.open (newfilename);





Note that you need to declare "newfilename" before you use it in the previous line (declaring it within the function is not enough because its scope is going to be within that function only).





I have rewritten your code and here is what I have:





string newoutput (string filename)


{


string newfilename;


int p = 0;





p = filename.find('.');


newfilename = filename.substr(0,p) + ".csv";


return newfilename;


}





string filename = "data1.txt";


string newfilename = newoutput(filename);


result.open(newfilename);


C++ Programming (array and string)?

Can someone do this code for me, i apperciate if the code is complete and ready to built and execute; this are the instruction:





Write a program that asked the user to enter a string. Then the program should ask the user to enter a letter. The program should serach for that letter in the string the user entered and REMOVE it from the string.





For example if the user enter: This is the string test


The enters the letter T


The program should print out: his is he sring es





Make the input/output "Friendly" Tell the user what the program will do and so on...





A few important things:


-Declare the array for the string at least 50 chars long


-Use #define for the array sizes


-USE FUNCTIONS, use at least one function. I used one funstion that took the string the user entered, an array to store the new string and the char. The prototype loked like this :


void remove_char ( char * string, char * newstr, char ltr);

C++ Programming (array and string)?
its a suggestion


never order other to do sth


better request or ask politely


and be happy with wat they give ya
Reply:Are you testing us or asking for help??
Reply:please do it when you get strunded then let me know


I want a program in "C" Language that reads 2 names into 2 string parameters then replaces between them

hi all


guess thats easy for some ppl, but not for me....





i just want to create a simple program in "C" language that reads 2 names with scanf function then it puts them into 2 string parameters then it replaces the names in the parameters with each others........








thats all








Notice,,,, the names' length isn't limited !!





thanks alot

I want a program in "C" Language that reads 2 names into 2 string parameters then replaces between them
#include %26lt;stdio.h%26gt;





void main()


{


char[] first, second, temp;


printf("Enter string: ");


scanf(%26amp;first);


printf("\n");


printf("Enter string: ");


scanf(%26amp;second);


printf("\n");


temp = second;


second = first;


first = temp;


}

imperial

I need an actual example of how to write a 'float function' in Visual Studio 2005 for C++!!!!!!!!!!!!!!!!!!!!!

i have the program Microsoft Visual Studio 2005





i am using this in my computer science class





i know how to properly write a 'string function' in C++ but in my homework assignment we need to write a 'string function' and a 'float function' and i have no idea what im doing wrong





i do exactly the same thing i do w/ the 'string function' to the 'float function' but it wont compile and i dont understand what the error is trying to tell me to fix, please god someone help me!!

I need an actual example of how to write a 'float function' in Visual Studio 2005 for C++!!!!!!!!!!!!!!!!!!!!!
When you ask a question like this in the future, it might help to also post the error that you get when compiling your code. It actually can tell you a lot!





Based on the code you posted, I see a couple of problems:





1) You function signature: float findarea (float h, float a, float b);


Doesn't match your function definition: float findarea (float h, float a, float b, float area)





That will be a problem. Looks like you can eliminate the 'float area' variable and they should match then. Remember that the signature you put at the beginning of your code needs to match the function you write later on!





2) when you call findarea: cout %26lt;%26lt; findarea;


You are not passing any of the variables! You need to send the variables to the function for it to do any work. You probably want: cout %26lt;%26lt; findarea(h, a, b);





3) Finally, in the function itself, you do work on the variable 'area' but you return an unitialized variable 'testarea'. You probably want:





float findarea (float h, float a, float b, float area)


{


return ((1/2)*(h))*(a+b);


}








If you still have problems, you probably should post a new question with the part of the code that matters and the error messages that you are seeing when you compile. But I think these three changes will compile OK for you (assuming you make the same kind of changes to your other functions). There is nothing special about float functions, you just need to brush up on the rules for writing functions in general.





Good Luck!
Reply:Can you post your code? Do you just need a function that handles floating point numbers?





float division(float x, float y){


return x/y;


}





int main(){


cout%26lt;%26lt;division(10,3)%26lt;%26lt;endl;


}
Reply:Edit your question and put in the code you are trying to use...we can't really help you with your errors unless we see the code. This also allows people to see that you did give it some effort and you need help rather than looking for homework answers.


Convert string to integer in C, without using itoa function?

Basically, I want to know what's "behind" itoa... A site which explains/expands functions in C would be useful, too.

Convert string to integer in C, without using itoa function?
void itoa (char *buf, int base, int d)


{


char *p = buf;


char *p1, *p2;


unsigned long ud = d;


int divisor = 10;





/* If %d is specified and D is minus, put `-' in the head. */


if (base == 'd' %26amp;%26amp; d %26lt; 0)


{


*p++ = '-';


buf++;


ud = -d;


}


else if (base == 'x')


divisor = 16;





/* Divide US by divisor until UD == 0. */


do


{


int remainder = ud % divisor;





*p++ = (remainder %26lt; 10) ? remainder + '0' : remainder + 'a' - 10;


} while (ud /= divisor);








/* hex values */


if(base == 'x')


{


*p++ = 'x';


*p++ = '0';


}





/* Reverse it */


*p = 0;


p1 = buf;


p2 = p - 1;


while (p1 %26lt; p2)


{


char tmp = *p1;


*p1 = *p2;


*p2 = tmp;


p1++;


p2--;


}


}
Reply:I don't know what is behind itoa... however, I did oncewrite a c function to convert integer to individual asci codes, then display it using my own little text system for GBA using HAM





here is the smaller one, does 4 digits from an unsigned 16 bit number...





void Draw_4dd(u16 num,u8 nx,u8 ny)


{


if(num%26gt;9999)num=9999;





u16 Th=0;


u16 Hu=0;


u16 Te=0;


u16 On=0;





Th= (num/1000);


Hu= ((num-(Th*1000))/100);


Te= ((num-(Th*1000)-(Hu*100))/10);


On= (num-(Th*1000)-(Hu*100)-(Te*10));





Th=Th+48;


Hu=Hu+48;


Te=Te+48;


On=On+48;





if(num%26gt;999)


Draw_Text(Th,nx,ny);


if(num%26gt;99)


Draw_Text(Hu,nx+1,ny);


if(num%26gt;9)


Draw_Text(Te,nx+2,ny);


Draw_Text(On,nx+3,ny);


}





u16 and u8 are unsigned 16 and 8 bit vars. I break the number down into ten's place values, then add the code for 1(48) to them(giving me the asci codes for the numbers), then pass it to my single charector text plotter function Draw_Text I was going to write a faster version of this, but never got to it. the only thing that makes this work is the fact that integer values don't keep a decimal value. when you divide 1234 by 1000, you still get 1 as a result. multiply back by 1000, you get 1000. the fact that the computer is in 2 base is irrelevant, because i use a seperate var for each 10 place value.





converting string to integer would be the same thing backwards





what I would do is treat the string as an array, walking through each char, from the end to the front, multiplying each new number by the next ten power, then adding it to an accumulating integer variable. You would also have to look for indicators, like spaces, commas, dollar signs, and bad data, like letters...





hope this helps a little.
Reply:Ok... 124 = 100 + 20 + 4. In other words, 124 = 1*100 + 2*10 + 4*1. Get the idea?





The actual source code should have a more efficient algorithm, probably with binary math, logical shifts, shortcuts, etc. It could even be written in assembler. Many compilers do include the source code of their libraries.


Convert string to integer in C, without using atoi function?

Basically, I want to know what's "behind" atoi... A site which explains/expands functions in C would be useful, too.

Convert string to integer in C, without using atoi function?
Here is the simplest example. It's a bit clumsy as it doesn't check for overflow:





int my_atoi ( const char * s )


{


int n = 0;


if(!s) return 0;


while(*s)


{


if(*s%26lt;'0' || *s%26gt;'9')


return 0;


n = n * 10 + *s - '0';


s++;


}


return n;


}
Reply:just substract each character by '0'


What strings should I get for my cello?

I have a relatively bright cello. Right now I have Larsen A%26amp;D and Helicore G%26amp;C. I'll be changing strings right about christmas time, and I'm trying to figure out what kind of strings to get now. I was thinking about obligato, or a mix of obligato and oliv or evah. I was just wondering if anyone knew a site with cello string reviews, or has personal experience themselves. Thanks!

What strings should I get for my cello?
I would stick with Larsen A%26amp; D but switch to Prim for G%26amp;C they seem to balance very well (big bottom and bright top now that's a sight) I am very VERY happy with the Prim ... I switched to Larsen last year after many years with Jargar on top ... liked the change
Reply:www.amazon.com


i think obligato is one of the best brand for strings...
Reply:I always found Yargar strings to be the best for my cello. i have always liked the sound they produced and they seem to hold out really well for me also.

elephant ear

Character String Help in C?

I have a problem with character string manipulation, im trying to prompt the user to enter a float (i.e. a numerical value) but the user can decide to close the program if he/she enters "exit". I tried using the isdigit and isalpha functions, but they only return a value of 0, which would force me to re-prompt the user. Any suggestions on how to immediately quit the program once the user enters "exit" ?

Character String Help in C?
Read in the character array (string) value and then test it being equal to exit. If not, then use the atof() function to try and convert the value to a float.





For example,





char myChar[20];


float myVal=0.0;


scanf("%s",myChar);





if (strcmp(myChar,"exit")) {


/* input is NOT equal to exit */


myVal = atof(myChar);


...





myVal would then contain the numerical value of their input according to the conversion rules of atof().





(massiv_x: a "string" is a character array terminated by a null character; what you've given is actually in error because you've defined 27 bytes, BUT because the value is enclosed in double-quotes, it stores 28 bytes (including the null terminator.) You can't use any string functions with that variable as it doesn't contain space for the string terminator \0. Perhaps just a typo. ;)
Reply:if i recall...the isdigit and isalpha function take only a single value...





in c, strings are actually just character arrays...you know:


char thisstring[27] = "twenty-seven bytes of data.";





in order for your method to work, youll have to pass in every letter on by one...this wont work for your cause tho..


when you pass the values into isalpha or isdigit you have to use the array index with the string variable..if you dont, youre just passing in a memory pointer value..this may work for you, you just gotta access the array (string) directly from memory using pointers..