Sunday, August 2, 2009

C++: Changing a number into a string of chars?

How would I change an int variable which is 12345 into a char array with [1,2,3,4,5]?





Tell be the corresponding library please, if there is one.

C++: Changing a number into a string of chars?
Use sprintf.





char buf[32];


sprintf(buf, "%d", nValue);





where nValue is your int variable.
Reply:How about incorporating a straight c fix:





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


int yo = 12345;


char buf[30];


sprintf(buf, "%d", yo);





or if you use a char to hold initially 12345, then it is already in an array.





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


printf("%c\n", buf[i]);


Getting input from a text file using c strings in c++?

How do i get input from a text file using c strings, not the standard string class. Is it possible?

Getting input from a text file using c strings in c++?
Sure, as long as you use the #include%26lt;fstream%26gt; header, and name the file you want to use as input. When you parse the data, just store it to a C-String, which as you should know is an array made exclusively of characters.


C program recursive method (find the character index in the string)?

str = "Hello world"


ch = "w"


use recursive method, no string.h function


return 'w' index = 6





int findIndexString(char str[ ], char ch)

C program recursive method (find the character index in the string)?
again, like before! I really hv too much time in my hands today :-p





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





int findIndexString(char str[], char ch) {


int pos;


if (*str=='\0') {


return -1;


}


if(*str==ch) {


return 0;


}


pos = findIndexString(++str, ch);


if (pos%26lt;0) {


return pos;


} else {


return pos+1;


}


}


int main() {


char str[25]="hello world";


int pos = findIndexString(str, 'h');


printf("The position is %d\n", pos);


}
Reply:Hello,





I suppose this is just for fun? If so, ok.





Else please note It is particularly inefficient to use recursiveness for such low level functions. You put the system under heavy strain due to call stack adjustments needed to accomodate the numerous function calls (passing variables).
Reply:int findIndexString(char str[],char ch)


{


static int i=0;


if(*str =='\0')


return 0;


else if(*str == ch)


return i;


else{


i++;


return findIndexString(++str,ch);


}





}

nobile

I want to tokenize the string using the delimiter :some @.How to do this in C#.net?

Eg:suppose some string"My name@is xxx.@I am doing @so and so"


actually my intention is to store all these tokens in different variables.


let me say


x = My name


y = is xxx.


z =I am doing


a =so and so








Actally i know how to do it in java using the string tokezier.How to


do this in .Net.


Please help me.








Thanks in Advance..

I want to tokenize the string using the delimiter :some @.How to do this in C#.net?
string field = "My name@is xxx.@I am doing @so and so"


string[] result = field.Split(new char[]{'@'});


C++ codehow to input data into string like from file and than search for particular word in the string.?Thanks

if U have a file called f.txt for example U can make th following





freopen("f.txt","rt",stdin);





string s = "";





getline(cin,s); // this will read a line from the file





//now to search for a word use





s.strstr("Ur word"); // will return -1 in case the string is not found and the index of the start of the word otherwise





Regards,


Need a short c++ program that counts how many words in a string?

cin%26gt;%26gt;"this is a test"


cout%26lt;%26lt; x %26lt;%26lt; "words in your string";





where x is determined to be 4 by some short function.

Need a short c++ program that counts how many words in a string?
the simplest one would be to count the no. of spaces in the string and report %26lt;%26lt;no_of_spaces+1 .


that's ofcourse the most basic program.. and it'll give u wong results more often than not.





ican post u the exact code.. (the perfect program) for this.. if u really need.. but it'll ofcourse take some time
Reply:Oh come on -- this is too easy to ask for help with. How far are you going to get asking someone else to do your homework for you?





Look, this is the basic pseudocode:





x = 0


while not (end of string) do {


if (current character is a blank space){


if (next character is not a blank){


x = x + 1


}


}


}


return x





that's basically it.


How do you tune a 6 string electric guitar to drop d tuning and drop c tuning?

either with an electric tuner or without i have an electric tuner i just dont know what to tune it to for drop c and drop d

How do you tune a 6 string electric guitar to drop d tuning and drop c tuning?
Dropped C tuning is an alternative guitar tuning style in which the lowest (sixth) string is tuned down two tones ("dropped") to C and the rest of the strings are tuned down one tone, thus making the overall tuning CGCFAD from low to high. Although popularly referred to as "Drop C", CGCFAD tuning is not in fact "Drop C" tuning; a "drop" tuning refers only to the dropping of the tuning of the lowest string; thus "Drop C" tuning is actually CADGBE and the tuning referred to is actually "Drop D, tuned down one whole step (tone)."[1] Throughout the rest of this article, what is referred to as drop C is CGCFAD, or drop D tuned down one whole step.





Dropped D tuning: DADGBE, also known as simply as drop D, is an alternate guitar tuning style in which the lowest (sixth) string is tuned down one whole step ("dropped") to D rather than E as in standard tuning (EADGBE or EADG).,

flower girl dresses