Friday, July 31, 2009

How do u implement string functions using pointers in C?

i need a sample program involving strcpy n strcat

How do u implement string functions using pointers in C?
#include %26lt;stdio.h%26gt;


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





main() {


char* a = "hello ";//a is a pointer to a string "hello "


char* b = "world";//b is a pointer to a string "world"


char string1[strlen(a)+strlen(b)+1];//string1 is a pointer to a string of characters





strcpy(string1, a);//string1 now cantains a "hello " string


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





strcat(string1, b);//string1 now cantains hello world


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


}
Reply:The code example by jericbryledy is incorrect because no space has been allocated for string1 to contain the copied characters.





use malloc to provide space for the copied characters.





string1 = (char *)malloc(sizeof(char) * (strlen(a) + 1));


strcpy(string1, a);

sympathy flowers

The string of a piano that produces a middle c note vibrates with a frequency of 2.64x10(2) Hz.?

whats the speed of sound in air, if the sound waves produced by this string have a wavelength in air of 1.30m?

The string of a piano that produces a middle c note vibrates with a frequency of 2.64x10(2) Hz.?
Clue: what are the units of the Speed of sound? Meters/sec?





multiply the wavelentgh (m) by the frequency (sec^-1)





so 264 sec^-1 x 1.3 m = 343 m/s (1125 fps)





wer
Reply:beats the hell out of me. Ive been playing for 40 years. ( i have a failight and a babay grand a vox and a triton) been with bands for 25 years. Ive been considered a great touch and i can tune both the piano and figure out whats wrong electronically with my equipmetn. but i cant figure out why anyone would wantt o know this. except to waste his or her time. lol. seroiusly . just how much do you think the ear can hear? you remind me of the tone deaf singing. it just is chaotic and wrong. but if you make a better keyboard than whats out there. im all for it. ill play that too .though i cant imagine anyone noticing the difference. good luck!


The string of a piano that produces a middle "C" note vibrates with a frequency of 2.64x10(square root of 2)Hz

If the sound waves produced by this string have a wavelength in air of 1.30m, what is the speed of sound in air?

The string of a piano that produces a middle "C" note vibrates with a frequency of 2.64x10(square root of 2)Hz
The way that you typed the question has probably thrown everyone off. Middle C would be 264 Hz which can be written as 2.64 * 10². that is 'squared'; not 'square root'.





velocity = frequency * wavelength


= 264 * 1.30


= 343.2 metres per second.


How do you tune a six string electric guitar in standard C? (C F Bb Eb G C)?

DOES ANYBODY KNOW!!!!!?????

How do you tune a six string electric guitar in standard C? (C F Bb Eb G C)?
if you're dropping the tuning, you'll need heavier gauge strings to make up for the decreased tension. i suggest ernie ball 'not even slinky' strings, they're designed for lowered tunings.





other than that, you just tune to whatever you want. this is easiest, of course, with an electronic tuner.
Reply:correct, just tune everything two steps down. you get an extreamly heavy sound. alot of guitars can't handle the looseness of the stings and it sounds out of tune, or the strings rattle on the fretboard
Reply:calm down the easyest way is to buy an electric guitar tuner. i got one at guitar center for 20 bucks.
Reply:why don't you go and get a electric tuner? it's cheap.


Ca i get any saample code in C language for encryption and decryption of a string?

i wanna hav a sample code that gets a string as its input and uses some random numbers as the key values and encrypts the string. the same random numbers should be used to decrypt the string...

Ca i get any saample code in C language for encryption and decryption of a string?
take a look at this page:








simple encryption using table :


http://www.planet-source-code.com/vb/scr...
Reply:www.c++.com
Reply:www.programmersheaven.com

bridal flowers

C++: Cocatenating an int to the end of a string?

I need to know how to concatenate an int to a string, the simplist way possible.





Here is a snippet of my code (only elementCoefficients[index] is an int) :





string buildChemicalFormula(int elementCoefficients[])


{


string formula = "";


int index;


for(index = 0; index %26lt; numberOfElements; index++)


formula = formula + elements[index].chemicalSymbol + elementCoefficients[index];





size_t location;


size_t index1;


for(index1 = 0; index1 %26lt; formula.length(); index1++)


{


location = formula.find("0", 0);


if(location !=string::npos)


{


formula.erase(location-1, 2);


index1 = index1 - 2;


}


}





return formula;


}





When I try to create the new formula, the compiler outputs, " error C2676: binary '+' : 'std::basic_string%26lt;_Elem,_Traits,_Ax%26gt;' does not define this operator or a conversion to a type acceptable to the predefined operator".





I tried casting the ints to chars but didn't work.

C++: Cocatenating an int to the end of a string?
You should be able to use the itoa() function (integer to alpha). Here's more information. http://www.cplusplus.com/reference/clibr...
Reply:Do all your additions as int. When you are ready to print the string, use string + int and it will do automatic string conversion.


How do i use a string variable with input file handle in c++ ?

usually what i do is:





ifstream InputFile;


InputFile.open("sample.txt");





but instead of using a file name i want to use a string variable. This is what I have tried:





stream x = "sample.txt";


ifstream InputFile;


InputFile.open(x);





but it is not working ? anybody got suggestions ??

How do i use a string variable with input file handle in c++ ?
you want to use a string type, not stream. check documentation on the C++ STL libraries.





string input = //whatever is from the user


ifstream infile;


infile.open( input.c_str() );





...





"c_str()" just returns a char* buffer to methods that need it.
Reply:ok so what you need to do is declare a char array of string not a stream varaible








stream x ="blah blah" // wrong








char * x;





x = new char[10]; // or however long your characters are





// then





x = "text.txt"





ifstream InputFile;


InputFile.open(x);





// this should work also remeber to pick the iso mode for it good luck


How can we print a string(eg"College") on the screen in C without using any semi colon.?

WE have to write the program code to display the string "College" on the output screen without making the use of any semi colon in the code.PLZ HLP

How can we print a string(eg"College") on the screen in C without using any semi colon.?
put it in an if.





like


main()


{


if(printf("College"))


{


;


}


}


this should work
Reply:That, or you can use inline ASM to call the "printf" function:





__asm


{


push [edx], DWORD PTR "College"


call printf


}





I believe. It's been a while since I've implemented inline ASM (did it with my last game engine).


C++ Counting the number of words in a string?

How would you go about counting the number of words in a string and the number of occurences of each individual letter? Is there an easy way to do the counting or will I need to create like 26 different loops to do the counting?

C++ Counting the number of words in a string?
***note: the following code may not be completely accurate. it is meant to show a way to get the solution, but there may be bugs.





basically:





1) keep track of a word count using the # of spaces there are, not counting the 1st or last position.





2) keep track of a letter count, with the index of the array being the letter, and the contents being the # of occurances of that letter.





---





#include %26lt;stdio.h%26gt; /* standard in/output include file */


#include %26lt;string.h%26gt; /* include file for string functions */








#define MAXlength 50 /* max. length of test_string */








main()


{


char i, /* used as a counter */


ch, /* a temporary character */


strsz; /* the length of the string */





char test_string[MAXlength]; /* the string being dealt with */


char alpha_count[26]; /* the letter count (of 'aA'-'zZ') */


char word_count=0; /* the word count */





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


alpha_count[i]=0; /* set counts of letters to 0 */





/* --- insert code here for inputting the string from the user */





strsz=strlen(test_string); /*sets strsz to the lngth of the string */





for(i=0;i%26lt;strsz;i++) /* go through each character of the string */


{


if(test_string[i]==' ') /*if it's a space, and the space */


if((i%26gt;0)%26amp;%26amp;(i%26lt;(strsz-1)) /* is not at the beginning or end of */


word_count++; /* the string, increase the wordct. */





ch=toupper(test_string[i]); /* ch = uppercase of the letter */





if((ch%26gt;='A')%26amp;%26amp;(ch%26lt;='Z')) /* if it's a letter between 'A'-'Z' */


alpha_count[ch-'A']++; /* keep track of that letter */


}





printf("In '%s':\n,test_string);


printf("There are %d words.\n",word_count);


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


if(alpha_count[i]%26gt;0) /* don't show counts for letters that */


/* aren't there */


printf("There are %d '%c's\n",alpha_count[i],'a'+i);


}

wedding reception flowers

I need help completing this C code. Basically it asks user for input String and reverses it and changes cases.

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





char* strRev(char* line);


//your code here


char* str2Lower(char* line);





main(void){


//your code here


while(opt != 4){


printf("\n--------------------------...


printf("\nCST220 --- Assignment 2\n");


printf("Joe Smith XXX-YY-ZZZZ\n\n");


printf("Please choose the type operation\n");


printf("1. Reverse an string\n");


printf("2. Change an string to upper case\n");


printf("3. Change an string to lower case\n");


printf("4. End application (Exit)\n");


printf("Option: ");


scanf("%d", %26amp;opt);





if(opt != 4 %26amp;%26amp; (opt %26gt;= 1 %26amp;%26amp; opt %26lt;= 3)){


printf("\n\nPlease enter the string: ");


//your code here


if(opt == 1){


printf("\nThe reversed string is : %s", strRev(str));


}


else if(opt == 2){


printf("\nThe string in uppercase: %s", str2Upper(str));


}


else if(opt == 3){


printf("\nThe string in lowercase: %s", str2Lower(str));


}


}


}


}


char* strRev(char* line){


//your code here


return str2;


}





char* str2Upper(char* line){


//your code here


return str2;


}





char* str2Lower(char* line){


//your code here


return str2;


}

I need help completing this C code. Basically it asks user for input String and reverses it and changes cases.
#include %26lt;ctype.h%26gt;





char* strRev(char* line) {


char *str2, first;


str2 = line+strlen(line)-1;


while (str2%26gt;line) {


first = line;


*line = str2;


*str2 = first;


line++;


str2--;


}


return str2;


}





char* str2Upper(char* line) {


while( *line ) {


*line = toupper(*line);


line++;


}


return line;


}





char* str2Lower(char* line) {


while( *line ) {


*line = tolower(*line);


line++;


}


return line;


}


How can I grab user input using cin in C++ then take that and create a string with that name?

I am making a program for storing contact data for an assignment and need to know how I can make the string's name the same thing the user input. This is not for school :).

How can I grab user input using cin in C++ then take that and create a string with that name?
As far as I know there is no way of doing that directly, however, here is an idea of accomplishing a similar thing:





C++ has a data type (a thing to store data -- like an int, double, string, etc.) called a "hash map" (some people call it a "hash table", too, both are correct). It stores things in pairs of "key"s and "value"s. Some example keys and values for your program might be:





KEY (name) / VALUE (age):


Bob / 16


Sally / 17


Bill / 40





To create a hash table, first include the proper library for it (#include %26lt;map%26gt; where you include everything else such as iostream or string, etc.), and then somewhere in your program, declare it in the following way:





map%26lt;string, int%26gt; my_hash_map;





This creates a new map variable named "my_hash_map" which has strings for keys and ints for values (as in our example with names and ages).





To add a person and their age to the map, do the following:





my_hash_map["Bob"] = 16;


my_hash_map["Sally"] = 17;


my_hash_map["Bill"] = 40;





When you want to look up someone's age, you can do the following (prints "Bob's age is 16; Sally's age is 17; Bill's age is 40"):





cout %26lt;%26lt; "Bob's age is " %26lt;%26lt; my_hash_map["Bob"] %26lt;%26lt; "; Sally's age is " %26lt;%26lt; my_hash_map["Sally"] %26lt;%26lt; "; Bill's age is " %26lt;%26lt; my_hash_map["Bill"] %26lt;%26lt; endl;





You can find more information on hash maps including how to delete items at it's C++ Reference page: http://www.cplusplus.com/reference/stl/m... .


How Do I Get The Class Location In C#, Dont Know How To Formulate Connection String?

In JAVA I used to use a class which told me where the class was located. I'm trying to tell the application that the database is in the solution but how do i do it?





I've got an OLEDB database, but i dont know how to formulate the connection string. The database is inside the Visual Studio solution but I dont know how to tell it that.





Please help...

How Do I Get The Class Location In C#, Dont Know How To Formulate Connection String?
Right click on your solution explorer and select properties. Go to the settings tab, type a name for a new setting (like DatabaseConnectionString) and select [Connection String] as the type. A wizard will popup allowing you to select a database; select your database. From now on, you can access this connection string using the Settings namespace, it would be:





Settings.Default.DatabaseConnectionStr...





I find this method much easier for doing this than remembering how to formulate the connection string. Adding the DB to your application solution really doesn't do anything for connecting to it.
Reply:OLEDB won't give you anything about the connectionstring. You dont really need to know where it is located.


I am using MYSQL database and when installed that MYSQL connector I just added it to each page i needed to work with MYSQL like this:





using MYSQL.data;





this way I get all the classes I need to connect and work with my database.


I hope this helps you


Could anyone give me a C program to find substring from a string?

I kindly request U to give me the C program if U have,its Urgent.


I tried my level best but i dint get the result for some substring,


I Cant find out the logical error.So please help me.


Thanks in advance

Could anyone give me a C program to find substring from a string?
just use strstr.





Look at an open source copy of the code for strstr

flowers gifts

I want a program whith c++ (it should get a string a=[12 3;4 5.5] and put the numbers in a matrix )?

it should understand size of matrix and put numbers in it,s arrey

I want a program whith c++ (it should get a string a=[12 3;4 5.5] and put the numbers in a matrix )?
I didn't find out what exactly you want but if you mean that you must enter a string like [12,13,25.5,123,12] and the program puts them into a array it's very easy. else it's not the case you can mail me and I'll tell you the soloution.


NOTE: I didn't test the program cuz i'm right now at cofenet and it might not work correctly and depending on your compiler you may change some of lines. I recommend Microsoft Visual Studion 6 or Borland C++ for you








//this programs wrote in a old style and


//works with many compilers


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


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


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


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





void main()


{


double *array;


char string[255], *temp,*ptr, *tptr, number[10]; //or more


cout %26lt;%26lt; "Enter your desigered string: " %26lt;%26lt;endl;


cin.getline(string, 255);


temp = new char [strlen(string) + 1];


strcpy(temp , string);


int size;


ptr = strtok(temp, ',');


for (size = 1; ptr != NULL; size++)


ptr = strtok(NULL, ',');


array = new double [++size];


int i = 0;


ptr = strtok(string, ',');


strncpy(number, string + 1, ptr - string - 1); //ignore [


number[ptr - string] = '\0';


array [i] = atof(number);


tptr = ptr;


ptr = strtok(NULL, ',');


while (ptr != NULL)


{


strncpy(number, tptr + 1, ptr - tptr - 1);


number[ptr - tptr] = '\0';


array [++i] = atof(number);


tptr = ptr;


ptr = strtok(NULL, ',');


}


for (int j = 0; j %26lt; size; j++)


cout %26lt;%26lt; "The array [" %26lt;%26lt; j %26lt;%26lt; "] = " %26lt;%26lt; array[j] %26lt;%26lt; endl;


}


How will you count the number of characters including space in a string or group of words using C language?

the output has to shown





enter the whole name: Juan DeLa Cruz





No.of characters shown: 14


No. of strings: 3





something like this....


i have no idea about this....just a little about string,i dont know where should i put those...








looking forward for the reply..

How will you count the number of characters including space in a string or group of words using C language?
Should be somethink like this (written in "project style") :





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





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


{


const unsigned length= 40;


char name[length]; /* declare the variable used to store the name */


unsigned chars=0, strings=0, blank=1; /* declare the counters */





printf("Enter the string :\n");


fgets(name,length,stdin); /* read the string name from the screen */





/* while loop to count chars and string - strlen would be easier but you probably may not use it as it's a project. Stop when it meets the end of the array */


while(name[chars]!='\n' %26amp;%26amp; name[chars]!='\0')


{


if (name[chars]==' ') blank=1; /* remove all the blanks and count them in chars, remembering that we're in a "blank" phase. in case there are many following like in " Juan de la Cruiz " */


else


{


if (chars==0 || blank==1)


{ /* if the first char isn't a blank or after all the blank trailing, we begin a new string in the sentence */


strings++;


blank= 0; /* we're not in a "blank phase" anymore */


}


}


chars++; /* in any case, we advance in the string name */


}


printf("\nNumber of characters in the string is=%d",chars);


printf("\nNumber of strings is=%d\n\n",strings);


}
Reply:Been awhile since I messed with c or c++ but I would count as 14 characters...


plus a null?


isn't there something that will tell you length of string?


strlen


http://www.opengroup.org/onlinepubs/0000...
Reply:strlen()

daylily

What is a literal in C?Is it a)Stringb)String Constantc)Character d)Alphabet?

A literal is any piece of program whose value is apparant (obvious) from just reading it.


Such as an int, char, string, double literals:


soo an int literal would be 7


a char would be C


a double would be 7.6


a string would be "HIYA!"


Hope this helps! :)

What is a literal in C?Is it a)Stringb)String Constantc)Character d)Alphabet?
The answer is........ character ( i think)


Can you give me a c program of palindrome using string functions but without str reverse?

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





int isPalindromo( char *s ){


char *s2 = s + strlen( s ) - 1;


if( !*s )


return 1;


while( *s++ == *s2-- %26amp;%26amp; *s );


return !*s %26amp;%26amp; *( --s ) == *( ++s2 );


}





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


char s[255];





printf( "Texto:" );


gets( s );


printf( "%s \n", isPalindromo( s ) ? "YES" : "NO" );





system( "pause" );





return 0;


}


Write a program in c language to reverse a string using pointers?

These other guys are correct - you should not just throw out homework questions without making an attempt to learn yourself. In the case we are wrong, and you are stuck altogether, here is a dirt-simple program that will do what you need. I hope you learn something from this.





-----


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





/* here is your "test" string */


/* you will probably want to read you array


* from stdin or something, but this hard-coded


* version will serve to illustrate


*/


char original_string[64] = {"Testing 1 2 3"};


char reversed_string[64];





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


{


int i;


int count;


char* output_ptr;








count = strlen(original_string);





output_ptr = reversed_string + strlen(original_string) - 1;





for(i = 0; i %26lt; count; i++)


{


*(output_ptr - i) = *(original_string + i);


}





/* verify results */


printf("Original string: %s\n",original_string);


printf("Reversed string: %s\n",reversed_string);





}

Write a program in c language to reverse a string using pointers?
Why are you asking all these questions?


Do your own homework, for crying out loud.





If you need help with something, then post your code. Otherwise, it's just rude of you to ask other people to waste their time on you.
Reply:Show us what you have so far instead of putting no effort into it at all.


I need to write a C++ Program that determines if a given string is a palindrome?

I need help with this program.








Hint





Create a string variable (char str[80])


Convert the string to uppercase characters


Keep only the alphabetic characters.


Compare the first character with the last character. If they're are the same,


compare the next character.

I need to write a C++ Program that determines if a given string is a palindrome?
#include%26lt;stdio.h%26gt;


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


#define size 26





void main()


{


char strsrc[size];


char strtmp[size];





clrscr();


printf("\n Enter String:= "); gets(strsrc);





strcpy(strtmp,strsrc);


strrev(strtmp);





if(strcmp(strsrc,strtmp)==0)


printf("\n Entered string \"%s\" ispalindrome",strsrc);


else


printf("\n Entered string \"%s\" is not


palindrome",strsrc);


getch();


}

flamingo plant

A function in C that reads in a String of text and counts the number of characters including space in the text

The text max is 250

A function in C that reads in a String of text and counts the number of characters including space in the text
strlen(const char *s)
Reply:#include %26lt;string.h%26gt;


char str[250] = "Hellooo this is a test";


int len = strlen(str); //Len = 22


1.write a c program to accept a string and convert it to upper case without using to upper(),without using poi

here some code...





char str[20]="aBcdeG_er23d*d";


int index=0;





while(str[index]!='\0')


{





if ((str[index]%26gt;='a') %26amp;%26amp; (str[index]%26lt;='z'))


{


str[index]=str[index]-32


}





index++;


}





cout%26gt;%26gt;str%26gt;%26gt;endl;








thank you reading my poor help...

1.write a c program to accept a string and convert it to upper case without using to upper(),without using poi
Huge hint: www.asciitable.com
Reply:I don't know how to write in C, but I can trry to give you some basic ways of convertng to uppercase:


Im not sure what poi means but i think you could compare each letter in the string, using a loop, to an array containing the alphabet and create another identical string with uppercase letters, if that made any sence...





There is a way to compare each of the letters in the string variable in ascii format and i think you can then use a formula to convert that letter to uppercase


for example, in acsii, the decimal equivilant to "a" is "97" and "A" is "65", "b" is "98" and "B" is 66 and so on, so you can maybe make something like this (remember, I cant program is c..): if ((Integer)firstLetter.inASCII()%26gt;=97%26amp;%26amp;(In... then (Integer)firstLetter.inASCII()-22=newFir... I dont know if this made any sence to you, if I new more about C then I could be more specific, maybe you can go somewhre with this


Please write a c function to reverse a string , any one help me ?

I'll assume that you really want to learn from the assignment you are given, rather than just have someone give the answer to you outright.





To reverse a string, you need to first exchange the first and last characters in the string. So, figure out the index of the last character in the string, and this will be easy. You'll need to calculate the length of the string to do this.





With this done, you can continue the process by exchanging the second and next-to-last character of the string. In fact, you can write a loop to perform the appropriate exchanges until you are finished.





Figuring out the terminating condition of the loop requires a little thought, and you should consider the two cases of strings of odd and even length. Drawing a picture may help here.





Ultimately, this problem can be solved by breaking it into smaller problems, each of which can be solved with a little thought. This is what your instructor hopes you will do. Developing these problem solving skills is what will make you a valuable employee.

Please write a c function to reverse a string , any one help me ?
#include %26lt;string.h%26gt;


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


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











int main() {





char s[1000];


int i;


int len=0;





while (1) {





printf("\n\n\tEnter a string : ");


gets(s);





printf("\n");





for(i=0;s[i];i++) {


printf("%c",s[i]);


}


len=strlen(s);


printf("\n\n");


for(i=len-1; s[i], i%26gt;=0; i--)


printf("%c",s[i]);


}


return 0;


}
Reply:Hi, i dont remember exactly , but i can give u the steps, u have to try urself:


if the number is x,


then first take the remainder of this number dividing by 10, which will give you te last diggit of this number, get it printed,


then find the integer value of it while dividing by 10.


then repeat the above steps on this number.





example:


if number x = 123,


dividing by 10, will give the remainder as 3., so save ths number.


now dividing by 10 and finding the ointeger value, it will be 12,


again repeating the above step,


divide this number by 10 for finding remainder, which will be 2,again save ths number


and diving by 10 for finding integer value, u will get 1, which is the last digit, so save this also, now if u print in sequence, the saved numbers, u will get:


321,which is the reverse of the number x.
Reply:Do your homework! Hint... stack.


2.write a program in c to check if two string are same,dont use strings?

I will write steps to solve this problem. And I think, you will be able to solve this problem.





1) Get two strings (Input from user or any other source)


2) Compare the length of both strings. If length is not same, the strings are obviously different.


3) If above condition fails (means, the length of strings are same), write a loop (either for/while/do-while) and compare each character. Like 1st character of 1st string should be equal to 1st character of 2nd string and so on. If any of character is not matched, the strings are not the same.





We can use strcmp or similar function to do this. But your assignment is to not use this kind of functions, so u have to compare it in the way, i have described.

2.write a program in c to check if two string are same,dont use strings?
char string1[256];


char string2[256];





cin.getline(string1, 256);


cin.getline(string2, 256);





if(strcmp(string1, string2) == 0){


cout %26lt;%26lt; "Strings are equal";


}


else{


cout %26lt;%26lt; "Strings are not equal";


}
Reply:You can easily understand my code here (or already...).





bool CheckTwoStrings(char* str1,char* str2)


{





if(strlen(str1)!=strlen(str2)) return false;


/* If you don't want to use strlen, then here my strlen function below */





while(*str1!='\0')


{


if ((*str1)!=(*str2)) return false;


str1++;


str2++;


}





return true;





}





int strlen(char *p)


{


int i=0;


while(*p!=0)


{


i++;


p++;


}


return i;


}





then, i think it's almost up...


If you got anything not clear or better suggestion, then please call me... cruisernk@yahoo.com
Reply:Well, without using string class just compare them as ordinary arrays.. First the size (if it doesn't match then they can't be the same) and afterwards character by haracter...
Reply:All the above answers are correct. I would like to add that if you are not using strings, declare the variable as an array of characters. For example, char[20]....etc. Then, you can compare the two strings, character by character, using just one loop!


Hope this helps!


Good Luck!

umbrella plant

Write a C++ program that reads a string and print the number of digits, number of space, number of upper case?

thx 4 helping :)

Write a C++ program that reads a string and print the number of digits, number of space, number of upper case?
The previous reply didn't answer the exact question you asked, but did show you what to do. My code below does what you're asking for. The character counting is pretty basic stuff, so I thought I'd toss in some C++ tricks to make it interesting, and help you learn something.





One nice thing about setting up the code this way is that if your want to count a different set of characters, you don't have to do anything to the code in main( ).





#include %26lt;string%26gt;


#include %26lt;iostream%26gt;


#include %26lt;cctype%26gt;





using namespace std;





struct Counts {


int digit;


int space;


int upper;


Counts() {


digit = space = upper = 0;


}


void count(const string%26amp; s) {


for (string::const_iterator i = s.begin(); i != s.end(); i++) {


if (isdigit(*i)) ++digit;


else if (isspace(*i)) ++space;


else if (isupper(*i)) ++upper;


}


}


};





ostream%26amp; operator%26lt;%26lt;(ostream%26amp; os, const Counts%26amp; c) {


os %26lt;%26lt; ". digit = " %26lt;%26lt; c.digit %26lt;%26lt; endl;


os %26lt;%26lt; ". space = " %26lt;%26lt; c.space %26lt;%26lt; endl;


os %26lt;%26lt; ". upper = " %26lt;%26lt; c.upper %26lt;%26lt; endl;


return os;


}





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


string str;


struct Counts cnt;





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


getline(cin,str);


cnt.count(str);


cout %26lt;%26lt; "Counts:" %26lt;%26lt; endl %26lt;%26lt; cnt;


return 0;


}
Reply:#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;cctype%26gt;


using namespace std;


int main()


{


string text;


cout %26lt;%26lt; "Please enter the text and terminate with a period(.) and press enter:\n";


getline( cin, text, '.');


int t,


numberOfSpace = 0,


numberOfWords = 0;





bool fSpace = true;


for( t = 0; t %26lt; text.length(); ++t)


{


if( isspace( text[t]) )


{


++numberOfSpace;


fSpace = true;


}


else if( fSpace)


{


++numberOfWords;


fSpace = false;


}


}


cout %26lt;%26lt; "\nYour text contains: "


%26lt;%26lt; "\ncharacters: " %26lt;%26lt; text.length()


%26lt;%26lt; "\nwords: " %26lt;%26lt; numberOfWords


%26lt;%26lt; "\nspaces: " %26lt;%26lt; numberOfSpace


%26lt;%26lt; endl;





system("PAUSE");


return EXIT_SUCCESS;


}


Write a C program to convert prefix string to postfix?

it wud be helpful if u can convert it to C...








/*Convert prefix to postfix expression.








*/


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


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





//Prototype Declarations


void preToPostFix (char *preFixIn, char *exprOut);


int findExprLen (char *exprIn);





int main (void)


{


//Local Definitions


char preFixExpr[256] = "-+*ABC/EF";


char postFixExpr[256] = "";





//Statements


cout %26lt;%26lt; "Begin prefix to postfix conversion\n\n";





preToPostFix (preFixExpr, postFixExpr);


cout %26lt;%26lt; "Prefix expr: " %26lt;%26lt; preFixExpr %26lt;%26lt; endl;


cout %26lt;%26lt; "Postfix expr: " %26lt;%26lt; postFixExpr %26lt;%26lt; endl;





cout %26lt;%26lt; "\nEnd prefix to postfix conversion\n";


return 0;


}// main





/*==================== preToPostFix ====================


Convert prefix expression to postfix format.


Pre preFixIn is string containing prefix expression


expression can contain no errors/spaces


postFix is string variable to receive postfix


Post expression has been converted


*/


void preToPostFix (char *preFixIn,


char *postFix)


{


//Local Definitions


char operatr [2];


char postFix1[256];


char postFix2[256];


char temp [256];


int lenPreFix;





//Statements


if (strlen(preFixIn) == 1)


{


*postFix = *preFixIn;


*(postFix + 1) = '\0';


return;


} // if only operand





*operatr = *preFixIn;


*(operatr + 1) = '\0';





// Find first expression


lenPreFix = findExprLen (preFixIn + 1);


strncpy (temp, preFixIn + 1, lenPreFix);


*(temp + lenPreFix) = '\0';


preToPostFix (temp, postFix1);





// Find second expression


strcpy (temp, preFixIn + 1 + lenPreFix);


preToPostFix (temp, postFix2);





// Concatenate to postFix


strcpy (postFix, postFix1);


strcat (postFix, postFix2);


strcat (postFix, operatr);





return;


}// preToPostFix





/*==================== findExprLen ====================


Determine size of first prefix substring in an expression.


Pre exprIn contains prefix expression


Post size of expression is returned


*/


int findExprLen (char *exprIn)


{


//Local Definitions


int lenExpr1;


int lenExpr2;





//Statements


switch (*exprIn)


{


case '*':


case '/':


case '+':


case '-':


// Find length of first prefix expression


lenExpr1 = findExprLen (exprIn + 1);





// Find length of second prefix expression


lenExpr2 = findExprLen (exprIn + 1 + lenExpr1);


break;


default:


// base case--first char is operand


lenExpr1 = lenExpr2 = 0;


break;


} // switch


return lenExpr1 + lenExpr2 + 1;


}// findExprLen


How to convert byte array to string without using any loop ? .net c#?

I alreay did using loop as below





for ( int i =0; i%26lt; mybytearray.Length ; i++)


message = message + (char)mybytearray[i];


in which mybytearray is byte array


and message is string;


but dut to this spead is slows down.





plz help me.

How to convert byte array to string without using any loop ? .net c#?
Try The following Code:


byte [] arrBytes = new byte[10];


System.Text.Encoding.ASCII.GetString(a...





Also you can visit the Link:


http://geekswithblogs.net/timh/archive/2...





I hope this solves your Problem and is Good enough for being the Best Answer ;)
Reply:Thanks Report It

Reply:Thank s a lot. Report It

Reply:Will this help





' VB.NET to convert a string to a byte array


Public Shared Function StrToByteArray(str As String) As Byte()


Dim encoding As New System.Text.ASCIIEncoding()


Return encoding.GetBytes(str)


End Function 'StrToByteArray





// C# to convert a string to a byte array.


public static byte[] StrToByteArray(string str)


{


System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();


return encoding.GetBytes(str);


}





' VB.NET to convert a byte array to a string:


Dim dBytes As Byte() = ...


Dim str As String


Dim enc As New System.Text.ASCIIEncoding()


str = enc.GetString(dBytes)





// C# to convert a byte array to a string.


byte [] dBytes = ...


string str;


System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();


str = enc.GetString(dBytes);


How can I convert Uppercase string to lower case and Lowercase string to upper case in Turbo C++?

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


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


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


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


#define p "cool"


#define u "1IS2"


main()


{


clrscr();


char pass[30],uname[30],x;


printf("Username: ");


gets(uname);


printf("Password: ");


gets(pass);


if(strcmp(uname,u)==0%26amp;%26amp;strcmp(pass,p)=...


{


/*in here, i hav to print variable 'uname' to uppercase and variable 'pass' to lowercase, please help me out, you can edit this if you want*/


}


else


{


textcolor(12);


cprintf("Incorrect Username/Password");


puts("\nCheck capitalization/spelling");


}





getch();


return 0;


}





/*your help will be much appreciated*/

How can I convert Uppercase string to lower case and Lowercase string to upper case in Turbo C++?
include %26lt;ctype.h%26gt;


...


if(strcmp(uname,u)==0%26amp;%26amp;strcmp(...


{


printf("%s",toupper(uname));


printf("%s",tolower(pass));


}


...





I Hope it helps.
Reply:include %26lt;ctype.h%26gt;


if(strcmp(uname,u)==0%26amp;%26amp;strcmp(...


{


printf("%s",toupper(uname));


printf("%s",tolower(pass));


}





use the abv procedute to solve ur prblm
Reply:You got toupper and tolower functions to do that job...
Reply:Thats confusing

deliver flowers

In c++ how can I split a given string based on delimeter ?

For ex:


split (string , delimeter);


where split ("hello-world", "-")


returns "hello" and "world".








Thanks in advance.





-Maz

In c++ how can I split a given string based on delimeter ?
Use the function strtok





The function strtok is found in the C string library. It takes two arguments, both arrays of characters (i.e. arguments formally of type char *) which we will informally call strings





The first string is the string that we want to break up into tokens (in our case, that would be inString). The second string consists of a list of delimiters. These are characters which mark divisions between tokens.





When called, the function finds the first token in the string, marks the end of it with a \0 and returns a pointer to the start of that token. In other words, the return value is a string containing just the first token. Once we process that token and have finished with it, we can call strtok again. However this time we call it with a NULL pointer for the first string to indicate that we want the next token of the same original string. We proceed in this manner until strtok returns a NULL pointer, which indicates there are no more tokens left in the string to return.
Reply:#include%26lt;stdio.h%26gt;


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





char* split(char *str, char deli)


{


char *str2;


for(int i=0;str[i]!=deli;i++);


for(int j=i;str[j]!=NULL;j++)


{


str2[j-i]=str[j+1];


}


str2[j]=NULL;


str[i]=NULL;


return str2;


}





void main()


{


clrscr();


char *a = "Hello-World";


char *b = split(a,'-');


printf("\n a = %s", a);


printf("\n b = %s", b);


//*a will contain "Hello" And *b will contain "World".


getch();


}





i have not tested this code. i just made it ryt here for u only.
Reply:Does 'hello' and 'world' have to be two seperate strings?


If not, then all you have to do is look through the string, and replace the '-' with a space.


You don't need to use any functions on the string.


If it must be 2 strings from ONLY 2 words, then all you have to do is read each letter of a string and copy it to an array. You copy letters until you come to a '-' character. Then you add the number 0 to the array. Skip over the '-' and begin copying into another array until you get to the zero. Add the 0 to the second array. You must add a zero the the arrays because C/C++ strings are zero-terminated. If you tried to print a non-zero-terminated string, then your program could crash or there will be a lot of junk characters printed after the string.


.Program in c++ to remove all spaces in a string. e.g. "love you all" should look like "loveyouall"

The string "loveyouall" should be stored in the same string and not in new one.

.Program in c++ to remove all spaces in a string. e.g. "love you all" should look like "loveyouall"
This should work:





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;


void stripSpace(string %26amp;);


int main() {


string test("HKLM\ Software\Microsfot\ Windows\Current Version\Run");


stripSpace(test);


cout %26lt;%26lt; test %26lt;%26lt; endl;


return 0;


}


void stripSpace(string %26amp;str) {


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


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


str.erase(i,1);


i--;


}


}





Enjoy :)
Reply:If u ve programmed in Turbo C++ this might be helpful..





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


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


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


int main(void)


{


char s[50];


cout %26lt;%26lt;"\nEnter String to Truncate: ";


gets(s);


int len = strlen(s),j=0;


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


{


if(isspace(s[i]))


{


j=i;


for(;j%26lt;len-1;j++)


s[j] = s[j+1];


if(i!=j)


{


s[j] = '\0';


len--;


}


}


}


cout %26lt;%26lt;"\n\nAfter Trunc: "%26lt;%26lt; s;


}


In C language , how can a string be printed to the console , with an empty main body ?? Impossible ??

Right now I can't come up with a way to do it in C.





In C++ you can do this:





class X


{


public:


X()


{


printf("Hello World!\n");


}


};





X x;





void main()


{


}





The constructor for x gets called before main is run.


I just tested this using VC6.0, and it works.

In C language , how can a string be printed to the console , with an empty main body ?? Impossible ??
It's been a long time since I've worked with C, but I believe that if you clear the screen then use the method





cout %26lt;%26lt; "String"





That'll do it... If that doesn't work, try changing the direction of the pointer.
Reply:You can use #error, but that will print a message at compile time. Some compilers also allow you to display a message via #pragma, but again, that's at compile time.





You can do something like this:


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





#define OBRACKET {printf("Hello world\n");


#define CBRACKET }





main()


OBRACKET


CBRACKET








Another option is use my example above, but substitute atexit(foo); for printf(), then declare function foo as such:


void foo()


{


printf("Test\n");


}





There might also be a way to do it in C++, but I'm not sure.


In C++, what's the term 'string' mean?

Please be as descriptive in English as possible I'm new at this stuff. Thanks :).

In C++, what's the term 'string' mean?
string or string functions?








String functions are used in computer programming languages to manipulate a string or query information about a string (some do both).





Most computer programming languages that have a string datatype will have some string functions although it should be noted that there may be other low level ways within each language to handle strings directly. In object oriented languages, string functions are often implemented as properties and methods of string objects. In both Prolog and Erlang, a string is represented as a list (of character codes), therefore all list-manipulation procedures are applicable, though the latter also implements a set of such procedures that are string-specific.





The most basic example of a string function is the length(string) function. This function returns the length of a string literal.





eg. length("hello world") would return 11.





Other languages may have string functions with similar or exactly the same syntax or parameters or outcomes. For example in many languages the length function is usually represented as len(string). The below list of common functions aims to help limit this confusion.
Reply:Strings are also dynamic in nature. With a normal character array, once you hit the end, you're done. With the string, you can just keep appending characters to it, and it allocates storage for them dynamically so you can hold as many as you want.





The [ ] operators are overloaded so you can treat it like a normal character array and access specific elements.
Reply:It is an array of characters. Nothing more, nothing less.





They just made this commonly used construct into a new class type called "string" which can be defined and used much easier than creating an array yourself.
Reply:group of characters....


characters- single letter, number or symbol....





=D

floral bouquets

Basically,what is string sorting?Can I get a C++ program to sort a string?

On what basis is the srting sorted out?In alphabetical order?

Basically,what is string sorting?Can I get a C++ program to sort a string?
I'm pretty sure you have to write a program to sort a string yourself. are you trying to make some letters in alphabetical order or what? all i can think of right now is using something like a bubble sort to compare the different parts(letters, words, whatever) of the string to each other... sorry for the bad answer! hope you figure everything out =3


C++ How do you search through a string for a newline statement?

int count = 0;


string first;


while (text[count] != '/n')


{


first.push_back(text[count]);


count++;


}


cout %26lt;%26lt; endl %26lt;%26lt; first;





My compiler says I can't use the while statement because it is always true.

C++ How do you search through a string for a newline statement?
Hi - you're missing a "/" in your while statement.





the "/" statement is an escape character, and if you just say "/n", it sees it as part of the string. It's an impossible pattern in the string class, so it's always true. Try looking for "//n".





good luck -





Rob
Reply:Depends if you're using the String datatype or if you're using a character string thats ended with "/0" (I think). In your case it looks like you've got a character string.





You should be able to do:





int count = 0;


while( text[count] != '/0" )


{


if( text[count] == '/n' ) cout %26lt;%26lt; endl;


count++;


}





Or something like that. Not really sure what your objective is here.


How do i convert a string to a an integer in C# without parsing?

I have to create a flowchart/pseudocode on how to convert an integer to a string and vi versa without using the .ToString() method and without parsing.

How do i convert a string to a an integer in C# without parsing?
Really? I don't understand how you could possibly convert a string to an integer without parsing it? The only thing I can think of is doing some wacky object creating, using overloaded constuctors? I have been developing for awhile, and would love to see the solution (or at least a brief expanation) when you get it. Will you email it to me when you find out? (I am emailable through YA) Thanks!


I play a 12 string gitar, like the chords..e,c,g,f,am.bla bla..what kind of chords are these people playing in

like i saw at church in the band.,its not bar chords..but down the fret some..and not your regular..e,c,g,f,am,chords got any other ideas? they just play different than me..i want to learn what they are doing?know of any good sites with free info on..about that?help?thanks:]

I play a 12 string gitar, like the chords..e,c,g,f,am.bla bla..what kind of chords are these people playing in
When people restrict part of the fretboard, what they are doing is changing the key of the instrument. Instead of being an instrument based in the key of C, they change its key so they can play the same chord patterns without thinking of what the new or odd chords are.

dried flowers

How to transform a string into an int value in C#?

Here's my line of code:





x = int Console.ReadLine();





But the debug says I can't turn string to int, I know somethings wrong with my syntax, please help me out?





I want a user to type a number in and assign that number to "x".

How to transform a string into an int value in C#?
Hi im sorry if this is incorrect, but this is what i understand that you are trying to do.





int userInput = System.int32.Parse(Textbox.Text);


//Basically because you entered a number in a text box


//does not mean its a number and you can use it as a number


//its a string so you have to convert the string into an int


int x += userInput;





i hope that his helps Dude.
Reply:Assuming x is an integer declared as "int x", use:





x = Int32.Parse(Console.Readline());
Reply:int num = Convert.ToInt32(x);





or





int num = (int)x;





Hope this helps,





Cheers


C++ programming. My problems are with a String class.?

Good afternoon! :-)





How should I write it correctly?


1st function: void print(std::ostream%26amp; os);


2nd function: static void copy(String%26amp; string1, String string2); (it (I mean the second) copies the matter of string2 to string1)


The private members of the class are: unsigned int elementsNum; and char*pData; .


These were my "small" problems. My "big" problem is that I have to alter my program to be able to treat with UNICODE characters.





So, these (3) are my questions. Only one answer would help me a lot, so if you can answer just one of my questions, it would be lovely.





Thank you!!!





Domonkos

C++ programming. My problems are with a String class.?
(1) will end up being something like:





void String::print(std::ostream%26amp; os)


{


os %26lt;%26lt; pData;


}





3) has an obvious solution but non-trivial implementation - use templates, exactly like the STL has chosen to do. Write and get the class working for chars and then generalize it via templates to wchars and possibly alternate allocators.





2) This is harder to help you with without more info. What are your constructors, copy constructor, overloaded operators, append methods, etc., that you anticipate having in the class?
Reply:Hi,





This link may help you - http://www.jorendorff.com/articles/unico...





Also the book Win32 system programming has excellent explanation and examples on using unicode


http://www.amazon.com/gp/reader/02016346...


C-prog 2 chk if a given string is a palindrome using strrev?

actually the logic which i used was


char *s,*t ;


int x ;


printf("enter the string");


gets(s);


t=strrev(s);


x=strcmp(s,t);


if(x==0)


printf("palindrome");


else


printf("not palindrome");


getch();





the problem is that what ever string i enter the ouput says tht its a palindrome!!


friends ... plz help me out !!!???

C-prog 2 chk if a given string is a palindrome using strrev?
#include%26lt;stdio.h%26gt;


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





void main()


{


char s[20],t[20] ;


int x ;


printf("Enter the string : ");


gets(s);


strcpy(t,s);


strrev(s);


x=strcmp(s,t);


if(x==0)


printf("\nPalindrome");


else


printf("\nNot palindrome");


}





Actually strrev() reverses the original string,so in your program s %26amp; t were getting the same value irrespective of whatever you entered.Here I've copied the original value to t before reversing s.That solves your problem :)


also I would advise you not to use the gets() function as it is dangerous to use ,it may create problem in the memory structure,use scanf instead.
Reply:One major problem is in your program is you are using single character for s, and t; To declare string use





char s[10], t[10];


and modify your program accordingly














use strcmp() as follows


x=strcmp(*s, *t);
Reply:you r having x as integer and strcmp return %26lt;1or%26gt;1 if strings are not same so int converts a no like 0.something to zero,and string is always palindrome.just use statement


if(strcmp(s,t)) instead of putting value in x,it also decrease a variable in your program.
Reply:declare the char *s,*t as array


int s[10],t[10]


there u will get the perfect result.


Is there a way to break up a string into groups in c++?

I cant understand your question. On what basis you want ot create groups.


eg: group of vowels, consonents etc. Clarify it

Is there a way to break up a string into groups in c++?
I know C++ is similar to Java in many ways, but not exact. I don't know any C++, but in Java if you want to split up a String value, you can use the substring(int x, int y) method and store the values to a String[] (Array)..





String x = "Hello World!";


System.out.println(substring(3,7));





OUTPUT: lo W

gift baskets

How to delete a single character from a string in java or c++ at anyposition?

Java solution:


presuming your original String is s1 and index is the character position, we will create a string s2 containig the required content.


OK:


String s2=new String( s1.subSequence( 0,index - 1 ) ) ; //create a string containig the first part (from start to the character)


s2.concat( s1.subSequence( index+1,s1.length( ) ) ) ; //add the characters remainig from the character after index to the end of the first string.





Now s2 contains the required characters.


There a several ways of doing this..this is the one that popped in my mind right now :).


Have fun


P.S.: pay no attention to the spaces I left. Theyu are there because, without the the line doesn't display right (I think yahoo makes some subtitutions or something), so just delete the funny spaces :D

How to delete a single character from a string in java or c++ at anyposition?
First you hae to have clear concept on how string works in C++ and Java.


In C++, String is an array of charectar. So deleting is like deleting an entry from array, delete move all values after the value to be deleted one space ahead.





In Java, String is immutable, that means you can not change string. Ofcourse you can create new one whenever you need.for Java use substring method of String class to get a substring containing all previous value and another one containing all value after the charectar. Then concate those two string.


How can I get the elements of string from input in C++?

I will assume your using C strings as you have not specified what kind you are using.





say the string is "char [30] asdf" (cant remember if the asdf goes before the [30], sorry)





you basically treat it as an array. say you want element 3. its name is: asdf [3]





so say you want to cout asdf [3]





cout%26lt;%26lt;asdf [3];





there ya go! if i were you , i would check out www.cprogramming.com


if you need more help, email me


Write a "c' prog to accept two string&prog should delete char similar in both the string&print remain strings

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





main( int argc, char **argv )


{


char *s1 = argv[1];


char *s2 = argv[2];


int i;


char *cp;


int count[256];





memset( count, 0, sizeof( count ) );


for( cp = s1; *cp; cp++ )


count[*cp]++;


for( cp = s2; *cp; cp++ )


count[*cp]++;





printf( "unique characters in s1: " );


for( cp = s1; *cp; cp++ )


if( count[*cp] == 1 )


printf( "%c", *cp );


printf( "\nunique characters in s2: " );


for( cp = s2; *cp; cp++ )


if( count[*cp] == 1 )


printf( "%c", *cp );


printf( "\n" );


}


What string gauge would you suggest for c standard tuning?

i play guitar and this is the first time i have to play in a tuning below E And D


standard tuning


What gauge would be best for C

What string gauge would you suggest for c standard tuning?
a lot of it depends on how hard you play.





i play very aggressively, i guess, because i'm using 11's and only tune down 1/2 step - but my strings feel very "loose" and my strings can go out of tune within a few songs, especially when on stage. maybe it's just me?





you can play that low with 10's, i'm pretty sure, but you have to be very careful how you play - play softly, don't dig in too hard, that kind of thing.





me, i'd go up to 12's or 13's.





i'd probably have to. =)





make sure you get your guitar reintonated pretty quickly, cuz changing your string gauges that much will almost certainly require a change in the action and/or truss rod. if you can't do it yourself, take it to a guitar tech.








Saul

wedding

I want to know about the string value in the c# in detail that actually what it is?

String in C# is a class and hence all the variables would be reference type. As it is a class you would be having many methods which u can use on the string objects such as length, search, copy and compare, Also we would have the constructor and destructor functionality provided with it also we have garbage collector in C# hence memory allocated to the strings would be taken care off.


How can I get an string with spaces in c++?

Hello Rob,





If you want to input string with spaces then either you have to use gets() or cin.getline() function..





Example 1:





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


int main(void)


{


const SIZE = 100;


char msg[SIZE];


cout%26lt;%26lt;"Enter a string."%26lt;%26lt;endl;


cin.getline(msg,SIZE);


cout%26lt;%26lt;"The sentence you entered was"%26lt;%26lt;endl;


cout%26lt;%26lt;msg%26lt;%26lt;endl;


return 0;


}











For more information, see the following links :


http://www.functionx.com/cpp/examples/fs...


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


http://www.opengroup.org/onlinepubs/0096...


.


.

How can I get an string with spaces in c++?
getch();
Reply:use the gets function


How can CONVERSION STRING to FUNCTION in C?for example "f(x)=sin(x=3)+x?

you can't just do it.





compare the string to "sin" and then call the sin function





if(myString == "sin")


{


sin(x);


}





you're going to have to do the processing there though. I'd say consume characters to the first open-parenthesis, and then compare it, then consume what's inside the parenthesis.

How can CONVERSION STRING to FUNCTION in C?for example "f(x)=sin(x=3)+x?
The link below will get you close although it is in C#. Can't remember if C has an Eval function but the gyst is to take any string and break it down into its parts character by character. You will have to extract the variables (x in your case) and you will need to ask the caller what is the value for x. Not sure this is what you are looking for.





The other thought is to offer a function f that takes a value (x) and returns sin(x) and if no value is passed, the I guess you default x to be 3.
Reply:From the little information you gave, I can guess that you want the user to input some function as a string, and then make that as a function within the program dynamically. Well it is possible, but it is a very lengthy process, and certainly not something I would be doing now.


Write c program to delete one character from string without using string handling built in function of c?

e.g.


my string is "hello"


and i want to delete 'l'


so my abnswer will be : "heo"

Write c program to delete one character from string without using string handling built in function of c?
Here it is. Rewrite as you wish:





void Remove(char *p, char ch)


{





char *temp;


temp=p;


while (*temp!=NULL)


{


if (*temp==ch){


while (*temp!=NULL){


*temp=*(temp+1);


if (*temp!=NULL) temp++;


} /*end while*/


temp=p;


} /* end if*/


temp++;


}/*end while*/


} /*end Remove*/





EDIT: C passes everything by value (that is it creates a new variable it copies the contents of parameters into) EXCEPT arrays. It creates pointers to arrays. Thus, in this program the calling function I used is:





int main()


{


/* Declarations*/


char Array[50], ch;





printf("Enter a string:");


gets(Array);








printf("Enter a character to remove:");


ch=getc(stdin);


printf("Your string is:\n%s\n", Array);


Remove(Array, ch);


printf("Your string is:\n%s\n", Array);


return 0;


}








You can send it the name of the array or you can send it %26amp;array[0] or whatever you like.

flowers on line

Thursday, July 30, 2009

Convert string into integer with error in c#?

I have following script try to convert string to int64


Int64 MyCompanyID1 = Convert.ToInt64(MyCompany1);


which MyCompanyID1 is string contain "123"


but I get error: Input string was not in a correct format, so I changed to another script:


long MyCompanyID1 = Convert.ToInt64(MyCompany1);


I got same error, any help please? Thanks,

Convert string into integer with error in c#?
My guess is that there are some hidden characters in your string that you are not seeing. Are you sure your string is reallly "123" or are you grabbing it from another function call or input. You can easily tests this by simply setting


MyCompany1 = "123";


then running your convert. It works fine on my end. good luck!
Reply:MyCompanyID1 can't be a string containing "123", because you've already declared it as an integer.


What is String Concantenation in Turbo C programming?

I really need your response. Thanks a lot. godbless.

What is String Concantenation in Turbo C programming?
in addition to pick m answer, yes, it does combine two words into one and concatenation is a function that combines two or more string to one word. ^_^





i just realized...i didnt add any information except to tell you that it is a function in Turbo C ^_^
Reply:it combines two strings and leaves out any spaces.





Example





"me %26amp; you" + "me" = me%26amp;youme


Will the c programming language ever implement the string data type from c++?

I doubt it.





C++ was written as an extension to C





It's not common for an older language to inherit from a newer language, especially when that newer language was an extension on the previous.

Will the c programming language ever implement the string data type from c++?
it is not possible
Reply:Please C is sooo dial-up! Even C++ is outdated C# is the future embrace it and love it!
Reply:nope. that's why there's a c-post increment.


What are the variable factors that affect the pitch (frequency) of a vibrating string? How are these factors c

What are the variable factors that affect the pitch (frequency) of a vibrating string? How are these factors controlled in a stringed musical instrument such as a violin?

What are the variable factors that affect the pitch (frequency) of a vibrating string? How are these factors c
On a violin, the factors that control the pitch, assuming that it is adequately constructed, would be how the string is made to vibrate, that is a bow or finger plucking, and where you place your fingers on the fretboard. Of course, the quality of the sound depends on the player.
Reply:Tension on the strings simple as that. The tighter the string the higher the frequency of vibration and thusly the higher the pitch.

florist shop

Random String/Word Generator in C++?

I'm trying to figure out how to generate random words. They don't need to make sense. For instance: it can generate "dfgag" "sge" sdvbsvdv". It would be perferable to make it generate less than 7 chars.





I've tried looking online but I can't find anyone who has done this.





Does anyone have a function, a place online, or even pseudo code that can point me in the right direction?

Random String/Word Generator in C++?
#include %26lt;stdlib.h%26gt;


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





void rword (char *word)


{


int len = rand () % 6 + 1;


word [len] = 0;


while (len) word [--len] = 'a' + rand () % 26;


}





int main ()


{


char word[7];


srand(time(0));


while (1) {rword(word); printf ("%s\n", word);}


}
Reply:I would strongly encourage you to take a good C++ course or follow some tutorials.





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


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


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








static short getRandomNbr(short low, short high)


{


return(low + (short) ((double)(1 + high - low) * ((double)rand() / 100.0) / ((double)RAND_MAX / 100.0)));


} /* getRandomNbr() */








main()


{


register short i;


unsigned char answer[8];


unsigned int luck; // :)





memset(answer, 0, 8);





srand((unsigned int)(time((time_t *) 0)));





usleep((luck = 1000 + 80 * getRandomNbr(1, 10000)));





srand((unsigned int)(time((time_t *) 0)) + luck);





for (i = 0; i %26lt; getRandomNbr(1, 7); i ++)


{


answer[i] = (unsigned char) getRandomNbr((short)'a', (short)'z');


} // for





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





} // main()


What is the code for displaying reverse of a string using recursive function in C?

In C.

What is the code for displaying reverse of a string using recursive function in C?
printrestofstringbackwards()


{


if (last letter)


{


print letter


}


else


printrestofstringbackwards()


}








there's some psuedocode...have fun. see how you print something backwards is you print the rest of the word backwards then you print the first letter. and how you print the remainder backwards is you print the rest of it backwards, then the first letter...and so on until no word is left.
Reply:You only need to ask once. Reported as spam.


Write a function min that has three string parameters a, b, and c and returns the smallest?

(alphabetically). Use C language.


In C++, how do I use either string or char to input first & last name using only one variable?

The console should ask for an author name, then the user enters both first and last name together (eg. John Doe), then the console should display both first and last name, but only one variable must be used. I've tried declaring char[20] or string but neither will allow for whitespace between the names. Any help is appreciated, thanks.

In C++, how do I use either string or char to input first %26amp; last name using only one variable?
#include %26lt;stdio.h%26gt;


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


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


#include %26lt;iostream%26gt;








using namespace std;





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


char name[80];





do{





int opcion;


cout%26lt;%26lt;"Selecione lo que desea hacer: "%26lt;%26lt;endl;


cout%26lt;%26lt;"Push 1 for put name %26amp; last name."%26lt;%26lt;endl;


cout%26lt;%26lt;"Push 2 for view the name %26amp; last name, you entered."%26lt;%26lt;endl;


cout%26lt;%26lt;"Push 3 for exit."%26lt;%26lt;endl;


cin%26gt;%26gt;opcion;


switch(opcion){


case 1:


cout%26lt;%26lt;"write the name and the lastname"%26lt;%26lt;endl;


/*jump exact 1 character used for the opcion*/


cin.ignore(1);


/*you can use cin.getline for take a chain of characters


con.getline take teh char array for put in came,


the number of characters , and the last the cahracter for delimited


*/


cin.getline(name,80,'\n');


break;


case 2:


cout%26lt;%26lt;"the name and the lastname youe entered are: "%26lt;%26lt;endl;


cout%26lt;%26lt;name%26lt;%26lt;endl;


break;





case 3:


exit(0);


break;


default:


cout%26lt;%26lt;" invalid"%26lt;%26lt;endl;


break;


}





}while(true);


return 0;


}





with cin.getline() you can take all the incomming data bye

sympathy flowers

C: Why '&' not used to declare String or Character?

C questions. Pleas esend me this as early as possible





Regards





Varun

C: Why '%26amp;' not used to declare String or Character?
in c,%26amp; is used as a 'address of' operator,hence cannot be used to declare a character ,string and to declare u can use a pointer.
Reply:%26amp; symbol is a special symbol. You can give as a value for a string or a character. But any variable declartion should not start with symbols other than _(underscore). Usually %26amp; is used both as reference operator as well as "address operator". So it cant be used. Hope u understoold this.
Reply:%26amp; is a special charecter or symbol like $ # used as shortcuts
Reply:string in C is an array.


the symbol %26amp; can be represented as an character


char a='%26amp;';





a string example


char s[]="c%26amp;language";
Reply:%26amp; is address of operator in C


C++ programming, editing function to return string instead of char.?

This function used to return a single letter. How can I change it so it could return a string of 6 characters?





char pop(stack *s)


{


char pop;


pop=s-%26gt;cars[s-%26gt;top];


s-%26gt;cars[s-%26gt;top]='\0';


s-%26gt;top--;





return pop;


}

C++ programming, editing function to return string instead of char.?
Hi,





The variable name pop and function name cannot be same.


I suppose you are having a structure stack. something like this:





struc stack


{


char cars[10][7];


int top;


};





Also here I am considering u are using C language and want to store 10 cars each of whose name is of at the most of 6 characters.





char* pop_operation(stack *s)


{


char *pop;


pop=(char *)malloc(sizeof(char)*7); // In C++, use


// pop =new char[7];


strcpy(pop,s-%26gt;cars[s-%26gt;top]);


s-%26gt;cars[s-%26gt;top]='\0';


s-%26gt;top--;


return pop;


}








Where ever u r calling this function, note u have to declare a string pointer before by writing,





char *str;





and at the time of call as





str=pop_operation(strucure variable or pointer as u did earlier);





U can print it as u print other strings.





In case of further more clarifications, u may query me again.





OM NAMAH SHIVAY
Reply:What you are wanting to return is a C-String, or character array. Simply declare char pop as a array of 6 characters





char pop[5];





then fill the values into the pop array, and return the value when your done with the function.


In C++ how can enhance my text (string) output?

i need the code to enhance a text which i read it from consol and saved as string,how can i print this text to:


* Make one space and only one space between each word and another.Each sentence separator (ie. ? , ! , ',', ';' , ' .') should not have a space before it and should have only once after it. (and i don't know if it possible to start the word after separator with capital letter ).


EX:


string mystr;


mystr(cin.'/n');


// supose i read the string as :


hi how?are you?! im fine.


after reading i want to print (mystr) the text as:


Hi how? Are you?! Im fine.// look at spaces "only one space between each word" and notic the capital letter after seperator (ex. how? Are..)

In C++ how can enhance my text (string) output?
The trick behind this question is doing things in the right order.





1) Start with replacing each of the sentence separators for the same character followed by a space.


2) Next, replace all double spaces for a single space, and repeat this for as long as there are double spaces in the string.


3) Replace each combination of a space followed by any of the sentence separators for the sentence separators (in other words, remove any spaces before a sentence separator).


4) If they exist, remove the space at the beginning of the sentence and the space at the end of a sentence. Because of step 2, there can only be (at most) one space at the beginning or end.


5) If the last character isn't a period, add a period at the end.


6) Capitalize the first character of the string.


7) Look for sentence separators that are followed by a space; capitalize the character that follows the space.





I think that's it. I hope it helps.








PS: 'replace' is discussed on page 595 of Stroustrup's book.