Monday, May 24, 2010

Anybody genius in c++ programming .This question is specially to them........?

Describe about c-strings in c++ programming .mention its functions


and also advantages of using these strings while programming....

Anybody genius in c++ programming .This question is specially to them........?
Hope this will help u


http://www.cprogramming.com/tutorial/les...
Reply:What are c-strings?
Reply:You don't need to be a genius to answer that.





Don't be so specific like that - give _everyone_ an opportunity to help you. Otherwise it's called "looking a gift horse in the mouth".





Rawlyn.
Reply:yes indeed


How to check for anagrams in C++?

I need a program to check two entered strings of text and see if the strings entered are anagrams, disregarding the case of the letters, and ignoring spaces (i.e. "Mother in Law" and "Woman Hitler" are anagrams). The strings won't be any longer than 500 characters.





I can't figure out what to do with this because it has to use arrays, which I have never been good with, and the emphasis is supposed to be on use of c strings.





I do know that it essentially needs to do this: change the case of the two strings and remove anything that isn't a letter, then sort the letters, and finally determine if they are the same (are they anagrams?).





I'm trying to keep this "simple." Can anyone help me with a program that does this? Thanks SO MUCH in advance!

How to check for anagrams in C++?
Well, in programming, we always try to get a clear problem definition and logical solution before we start coding.





Oh wait...I was thinking of a palindrome...





Answering questions for people is like programming. We should think 1st. :-)





Yes, sorting is a good idea. And so is changing case....changing case before the sort will enable a clean sort...





1 - Change both strings to lowercase with _strlwr( char *string );





2 - sort both strings... see qsort() for a cheap easy solution that your compiler probably already has. All mine have had qsort().





3 - kill whitespace. You mite need to build a function for this...but qsort should have moved all the whitespace to the end (or begining) which makes it easier (especially if at end).


- You can kill trailing whitespace very easily by putting a null '\0' at the very first instance of white space, if whitespace is at the end, like so:


for(ii=0; ii%26lt; strlen(string); ii++)


if(string[ii] == ' ') // a space?


{


string[ii] = '\0'; ///kill it and cap the string


break; // we're done


}








4 - compare the two strings with strcmp(). If they match, they're anagrams





That's our flow plan and function ID.
Reply:so its a "string compare" your doing ? ;-)





on the first one, u could have a pointer.. basically u check a letter against the second string...





you either have true / false... you need a recurssive loop that checks till end of line / null





it will either return TRUE and exit that loop.. then get ++ the string1 .. and repeat scanning string2..





if it returns false, after the end of string2... obviously they aren't the same..





i would have an array or struct, with a flag in for each character.. 1 exists.. 0 doesn't exsist





then print results.. eg..





found =


not same letters =





and no i'm not gonna do the code, u've had enough clues to do ya own homework =)
Reply:It is not that easy. May be you can contact a C++ expert at websites like http://askexpert.info/


Strings in C#?

if a user enters the expression in a textbox e.g 3 + 5


what is the code in c# that will take the string and evaluate


the expression?

Strings in C#?
See the code here:


http://www.codeproject.com/KB/cs/evalcsc...





It shows how to implement an "eval" function that inputs a string and evaluates it as code. If it's added to your project with the imports, you could do something like:





MessageBox.Show(eval("3+4;").toString(...





If all you need to do is add numbers though, it's overkill and it would be better to scan through the string for the "+" and extract the numbers on opposite sides.
Reply:Tryparse(textBox1-%26gt;Text,num1);


Tryparse(textBox2-%26gt;Text;num2);


num3=num1*num2;





textBox3-%26gt;Text=num3.toString();


or


MessageBox(num3.toString());


If I am using cin<<x; (in C++) where x is char[20] then x takes value only before space. How 2 get full string

Firstly its cin%26gt;%26gt;


u'll also need the command getline()


Im not going to give everything away but u shld be able to figure it from here !

If I am using cin%26lt;%26lt;x; (in C++) where x is char[20] then x takes value only before space. How 2 get full string
First of all, it's cin %26gt;%26gt; x. cout %26lt;%26lt; goes to the left, cin to the right.





Second, use cin.getline to get a full string.

wedding

Can someone give me an algorithm in C# to obtain and get the number of occurences of a unique char in a string

You can use regular expressions or a series of IndexOf calls.





Assuming,


string searchString = "abcbdefb";


char charToFind = 'b';





Regular Expressions:


int numberOfChars = System.Text.RegularExpressions .Regex.Matches( searchString, charToFind.ToString() ).Count;





IndexOf:


int numberOfChars = 0;


int lastIndex = 0;


while(lastIndex %26lt; searchString.Length %26amp;%26amp; lastIndex %26gt; -1)


{


lastIndex = searchString.IndexOf( charToFind, lastIndex + 1);


if (lastIndex == -1) break;


numberOfChars++;


}

Can someone give me an algorithm in C# to obtain and get the number of occurences of a unique char in a string
Well for VB, its like Len("msg") or Len(TextBox1.Text) and it tells you how many characters are in that text box.


Is there c# program to convert 4 digit no to 4 thousand 6 hundred 3 ten 2 unit manner without using any string

how to convert 4 digit number to the following example?


Example. 4632 want to convert 4 thousand 6 hundred 3 ten 2 unit

Is there c# program to convert 4 digit no to 4 thousand 6 hundred 3 ten 2 unit manner without using any string
#include%26lt;stdio.h%26gt;


void main()


{


int num,n1,n2,n3,n4;


printf("\nEnter 4 digit number");


scanf("%d",num); //ex4632





n1 = num/1000; //n1=4


n2 = (num/100)%10 //n2=6


n3 = (num/10)%10 // n3=3


n4 = num % 10 // n4 = 2





printf("\n %d = %d thousand %d hundred %d ten $d unit",num,n1,n2,n3,n4);


}





This is the only sensible solution dude.
Reply:Without using string it is not possible. otherwise the question is incomplete try to explain it with more details.
Reply:Without using a string? Ouch. How would you store the literal string "thousand" without using a string? You'd probably have to output it one character at a time, 't', 'h', 'o', 'u'....





In fact, the "string" type was created specifically so you didn't have to do that sort of silly char-at-a-time stuff. Why are you trying to do it the hard way? A sadistic professor? :)


Can anybody help me in coding in c to arrange the words in ascending order of word length given in a string?

Quicksort

Can anybody help me in coding in c to arrange the words in ascending order of word length given in a string?
Yes just sort it.
Reply:find the length of the string using strlen and sort the words using any sorting technique(Bubble sort)


Write a program in C# to sort the student list based on their names. The list is stored in a string array.?

Array.Sort( studentArray );





Anything else?

Write a program in C# to sort the student list based on their names. The list is stored in a string array.?
do your own homework.

flowers on line

Passing strings in C?

I'm pretty new to C and need help with strings. I also have no idea about the differences between C and C++, so please only help with info on C and not C++ or C#.





If I created a string in a function and want to pass it as a return value for the function to use in other functions, how can I do this without loosing the string when the function ends?





I know that when a function ends, everything that is local to it gets, for a better word, destroyed. If you can only return/pass the pointer to the string created in the function, when the function ends, won't the actual string be destroyed/reallocated and the pointer be essentially useless? How can I return the actual string/keep it for use in other functions?

Passing strings in C?
ok.... you have the basics right. so this is what you need to do





char * foo() {


int str_size = 6; //example size.


char * x = (char *) malloc(sizeof(char)*str_size);


sprintf(x, "%s", "hello");


return x;


}





the malloc is allocation memory from the heap. this will ensure that even when you exit the foo method, the location is not reclaimed. And you return the address to the same.


So you should be fine.
Reply:but don't forget to free() the pointer when you don't need it anymore, otherwise you will have a memory leak.


In c++, what is the difference between a character array (or a pointer to one) and a literal string?

In c and in c++ a character array is an array of bytes, normally containing ASCII values. A literal string is an sequence of ASCII characters terminated with a null ('\0'). Example:





char array[9] = { 'a','b','c','d','e','f','g','h','i','j' };


char str[] = "abcdefghij";


char *ptr = "abcdefghij";





array[] will contain the ASCII string 'abcdefghij' without a null string terminator: example array[] contains:





[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]


a b c d e f g h i j





str[] contains:


[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]


a b c d e f g h i j '\0'





ptr will contain the address of the first byte of the literal string "abcdefghij"; ptr+10 will be the address of the null terminator.

In c++, what is the difference between a character array (or a pointer to one) and a literal string?
there is some difference in memory assignment and accesing if you put alignment larger than 1. Say compiler option alignment is 8, then compile will assign 8 byte space for one char. For string, it assignes memory space for each char either one byte (ANSI) or two bytes (unicode).





Therefore, accessing those char in array will be more complicated


How to create a C program that will count the number of VOWELS and CONSONANTS in a inputted string?

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





void count(const char *str,


unsigned int *vowels,


unsigned int *constants) {


char *s = str;


*vowels = 0;


*constants = 0;





while (s) {


switch (tolower(*s)) {


case 'a':


case 'e':


case 'i':


case 'o':


case 'u':


(*vowels)++;


break;


default:


if (isalpha(*s))


(*constants)++;


}


s++;


}


}








Umm... Sorry, but can you explain what the most efficient way using library calls?

How to create a C program that will count the number of VOWELS and CONSONANTS in a inputted string?
2 ways to do this one is very basic and innefficient the other can be very complex but using existing library functions to do the work for ya





basic way is just a loop and compare one character at a time for any of the vowels





the other is to check out the string.h library


read the functions closely there is more than 1 way to do it


I have to input integer for c++ code how can i check whether the user input integer or a string character?

then if he input a charecter how to promt him to enter integer again

I have to input integer for c++ code how can i check whether the user input integer or a string character?
there are functions available in ctype.h header


isalph()


isalnum()


isdigit()


use them
Reply:all input is char values, they must be converted to int values, I believe 0 the character 0 is equal to 32, but you can say





if(x%26gt;='0' || x%26lt;'9') then


{


cout%26lt;%26lt;"This character is a number"


}





if you then wanted to convert it to a real number just subtract the character 0 from it IE '9' - '0' = 9

florist shop

C :Wat is the difference in using a strlen() and sizeof() function in the case of a string or character array?

Please explain with an example....

C :Wat is the difference in using a strlen() and sizeof() function in the case of a string or character array?
strlen() gives the length of the string whereas the sizeof() gives the size occupied by the variable.since character occupies only one byte,the sizeof() returns the total memory occupied by it whereas strlen() gives the present length of the char array.


eg:


char a[10]={'s','a');


sizeof(a) will return 10.


strlen(a) will return 2.








dear Raven,


Array implicitly doesn't mean it is a two dimensionsional thing.it can be n dimensional. for this example i've chosen a single dimensional array.
Reply:string length is one dimensional length only.


in an array you also have to define coloum size.


How do i write a c language program that gives the output as all possible combinations of a string input by?

user.

How do i write a c language program that gives the output as all possible combinations of a string input by?
As amazing as this may sound, this is something you can actually write in approximately 20 lines of code. You can use a FOR loop inside of a recursive function to do most of the work. Use the FOR loop to break down a string into smaller sub-sections for each recursion. This example will hopefully give you an idea of what happens.





eg.





[abcd]





├ [a] - [bcd]





├┬ [ab] - [cd]


││


│├┬ [abc] - [d]


│││


││└─ [abcd] - [ ]


││


│└┬ [abd] - [c]


│   │


│   └─ [abdc] - [ ]





├ [b] - [acd]








Pay close attention to these two lines.





├ [a] - [bcd]





├┬ [ab] - [cd]





In the second string, [bcd], the first character, [b], is appended to the first string, [a]. In the next step,





├┬ [ab] - [cd]


││


│├┬ [abc] - [d]








the same thing occurs. In the last step,





│├┬ [abc] - [d]


│││


││└─ [abcd] - [ ]





the same thing occurs. However, this time the second string has no characters to add to the first string, so you would add the first string to an array or output it. In the next step,





├┬ [ab] - [cd]


││


│├┬


│││


││└─


││


│└┬ [abd] - [c]








you'll notice the second character of the second string is appended to the first string. This is where you want to use a FOR loop to cycle through the string. I'll leave it up to you on how to actually implement this. If you need any more help or are confused, send me an email.
Reply:could u explain your problem statement better...


C program for deleting those words starting with s n ending with letter d in a string without using pointers.?

Without using pointers is not really possible.


You can use the string as an index like this;


if (s[i] == ........


but actually s[i] is still a pointer.


Anyway you can avoid using * and %26amp; this way, if hats what you mean?


Then write your own string search functions.


the standard string search and compare functions are returning pointers.


In c# which function is used to check whether a character is present in a string. give the syntax of function?

int iPos= strSource.IndexOf(strToFind);





if ( iPos != -1 )


{


// found strToFind (which could be just a single character) inside strSource.


}

In c# which function is used to check whether a character is present in a string. give the syntax of function?
I believe it's IndexOf();





tempString.indexOf(character);





Returns -1 if it isn't in there anywhere.

sympathy flowers

I need a C code for remove extra spaces from a text (without using the string.h library)?

See the following program I've tested with http://www.delorie.com/djgpp/compile/





Assuming you have a Zero-delimited, char-based ASCII text (i.e. you're using pure ascii, not a unicoded string) you can use the same algorithm:


/*


This program gets the spaced string " spaced " and prints an unspaced string between angles.


Note: this algorithm will modify original string.


*/





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


int main (void){


/*


This is the original string. Will be overwrited with zeros at its end.


*/


char *trimthis=" spaced ";





/*


This is the destination string:


*/


char *tramthis;





int begin, lasttext, pointer;





/*1- Get first nonspacing char */


begin=0;


while (trimthis[begin]==32) { begin++; }





/*2- Get last nonspacing char */


pointer=begin;


lasttext=pointer;


while (trimthis[pointer]!=0) {


if (trimthis[pointer]!=32)


{


lasttext=pointer;


}


pointer++;


}


/* Get right before the last nonspacing char */


lasttext++;


/* A bit of caution before we overwrite*/


if (lasttext%26gt;pointer) lasttext=pointer;





/* Overwrite just right after the last nonspacing char */


trimthis[lasttext]=0;


(void *)tramthis=(void *)trimthis+begin;





/* Print "%26gt;unspaced%26lt;" from " spaced " */


printf("%26gt;un%s%26lt;",tramthis);





return 0;


}


Is there a C function that will take an integer and output it as a string?

example an input of 256 will output two hundred and fifty six or something similar

Is there a C function that will take an integer and output it as a string?
try sprintf(). It's like printf, but it puts the formatted output to a string.





sprintf(stringName,"%d",intigerName);


that should work. I'm not sure what header sprintf() is defined in, i think its in one of the main ones.
Reply:No, but I found this functionality:


#include %26lt;sstream%26gt;





template %26lt;class T%26gt;


inline std::string to_string (const T%26amp; t)


{


std::stringstream ss;


ss %26lt;%26lt; t;


return ss.str();


}





Now if you are wanting to display the words for the numbers you'll have a lot more work. You have to parse the string, keep track of where you are, 10's, 100's, 1000's etc., and display the appropriate wording for each position and number. Have fun.


Am reading my values from a database, which is supposed to be a String but somtimes it may be a double. How c?

If you save a numeric variable to a string type field (char or varchar etc) it is saved as a string. When you read the data your software may still interpret it as numeric. It is up to the programmer to ensure any actions carried out first convert it to string type. This is software rather than database function. A hint at the problem this causes you may help us to guide you.

Am reading my values from a database, which is supposed to be a String but somtimes it may be a double. How c?
I understand what you're saying, but what's the question?


What gauge string for my guitar will work with standard tuning, drop d tuning, and drop c (c g c f a d)?

For serious drop tunings the heavier the better. The heavy gauge of the strings makes them less floppy due to the smaller amount of tension needed to bring them up, or down, to the desired pitch. I have a custom built Les Paul-copy strung with GHS Zakk Wylde Signature strings. They run from 10-60. I had to have my tuning peg and nut drilled and slotted. The only problem you may run into is a "muddy" sound from not having your guitar set-up properly. If you're capable, more power... send me some tips. Otherwise, take it to a shop and have it adjusted.

What gauge string for my guitar will work with standard tuning, drop d tuning, and drop c (c g c f a d)?
Any gauge will work with any tuning. It's all a matter of personal preference. I prefer to use .011's for their tonal qualities: much fuller and less tinny than lighter gauge strings although you have to work a little harder when bending, etc.

bridal flowers

In c++, how do I convert a variable of char* type to Std::string type.?

declare array e.g





char a[]={'1','2','3','x','y'};





there is no other functions to do it ansi C.


u have to put it in an array. then its a string.

In c++, how do I convert a variable of char* type to Std::string type.?
Yes there's a constructor that takes const char* for basic_string. std::string%26lt;char%26gt;.





PS: mac, again, you have no idea what you're talking about!!! ANSI C??? Please do not answer what you don't have a clue about.
Reply:Is there not a contructor for Std::string that takes a char*?


What is the source code to sort a linked list in C? Strings are what to be sorted.?

It's a linked list of structures with strings. The whole program is like a directory. The string is the name. We must sort it out alphabetically as we enter the data. Kind of frustrating that I have to do ask this.

What is the source code to sort a linked list in C? Strings are what to be sorted.?
Instead of sorting the list after entering the node, you must sort it while inserting the node. Whenever you add a new node compare it with all the nodes already present in the linked list and insert it accordingly. The "head" pointer points to the first node and the successive "next" pointers point to the nodes that are (alphabetically) smaller than the current node.





This is just kind of a rough algorithm. Try to code it, hope you got it.
Reply:When creating linked lists I make sure a prototypical comparison method exists. This method is generally customized for each type making use of the template.





Like strcmp() the method is intended to return less than zero if the left operand is less than the right, zero if equal, and greater than zero if the left operand is greater than the right.





Two sorting methods are provided (as overloads of each other.) One is the general sort which will do the basic ascending or descending values of the list. The other accepts a function pointer that allows for a custom sorting algorithm.





An example of a custom sorting algorithm is a randomizer; it simply returns one of the three expected returns at random. :-)
Reply:That is not easy. May be you can contact a C expert at websites like http://askexpert.info/


In C#.net which function is used to find the value of a string.?

use atoi(char) to convert char to int.


use atol(char) to convert char to long.


use atof(char) to convert char to float.

In C#.net which function is used to find the value of a string.?
strlen


I have a string of length 500 and Iwant to create an array of strings of 50 characters each how to do it in C?

char aOriginalArray[500];


char aNewArrays[10][50];





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


{


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


{


aNewArrarys[i][j] = aOriginalArray[ (i * 50) + j ];


}


}





There are cleaner ways of doing it using memcpy, but if you're asking this question, your prof. probably would want something like the above.

I have a string of length 500 and Iwant to create an array of strings of 50 characters each how to do it in C?
I know that in VB-6 there is a SPLIT() function that returns an array...Not sure how to do it in C, but you might want to check out http://www.pscode.com - I use that site all the time and it has great snippets.
Reply:u shud try two dimenstional array





char [10][50];





BOL





Amit
Reply:Good quetion


the Program is as follows


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


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


void main()


{


char a[500];


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


{


printf("Enter the strings");


scanf("%s",%26amp;a[500]);


}


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


printf("%d",a[500]);


getch();


}

wedding reception flowers

C++ help In Write a program that prompts the user to input a string and outputs the string in uppercase lette

help on how this works

C++ help In Write a program that prompts the user to input a string and outputs the string in uppercase lette
The way I would basically approach this problem:





Have the user enter a string or c-string.





for (int i = 0; word[i] != '/0'; i++)


{


then inside the for loop try something like:





word[i] = word[i].toupper;


}





I never had to do this but try looking up toUpper in your book.





Epic
Reply:I reccomend reading your textbook, which will give you the knowledge you need to answer your homework question.
Reply:Ya i agree you need to get a book like i have the C++ for dummies
Reply:You will need to use std::cin, std::cout, std::string and string.toUpper.





Reference your textbook to figure out how they are used.
Reply:u have to use toupper


read it here


http://www.cplusplus.com/reference/clibr...


In c# which function is used to get the last character in a string. how to remove that character from string.?

You can access the last character in a string by treating the string as an array, eg:


lastChar = str[str.Length-1];





To remove it you can use substring to return all but the last character, eg:


str2 = str.Substring(0, str.Length-1);

In c# which function is used to get the last character in a string. how to remove that character from string.?
int k=strlen(str) //where str is ur original string





for ( int i = 0 ; i%26lt;k-1; i++)


{


str1[i]=str[i];


}





// where str1 is some new string name, where your previous string will be saved without the last character





your new string str1 will have all your string data without the last character.
Reply:just get the string length then set the length - 1 to 0.





length = strlen(string)


string[length - 1] = 0


String ABCDE -one end fixed -w1 and w2 at B and C.passes around smooth peg at D (tension,w1,w2)?

D carries a weight of 400N at E

String ABCDE -one end fixed -w1 and w2 at B and C.passes around smooth peg at D (tension,w1,w2)?
I need either a picture of the layout or a better description of where A is anchored in relation to the pin at D. Are they at the same height? Are they aligned vertically? Is there some angle involved? Please elaborate so that I can help you.





NEW:


Thanks for the additional information. But even with that info I cannot get a valid solution for the weights at B and C. Either I am not understanding your description of the problem or there is a problem in the question itself.





But I can tell you that the tension in the rope is constant at 400N at all points. If it were not constant at all points along the rope then that force imbalance would cause the string to accelerate in the direction of the larger force, and this problem is a statics problem.





Sorry I couldn't give you an answer to all parts of the question. If you have any other details to add feel free to do so, because this problem is frustrating me. :)


How do you dump hex to a file using c++?

I have a c++ string of data. I want to dump this data as hex to a file. I'm not talking about just converting each character to its hex representation. I want to actually dump binary to a file.

How do you dump hex to a file using c++?
ofstream outf;


outf.open("dump", ios::binary);


ios::binary informs open that no translation of data to file is to be performed.


Basically, you write '\n' to a data file in text, it translates to '\r\n'


'\r' by itself does not get translated.


outf.write(data, data_size);


outf.close();

flowers gifts

How do you go about solving this basic C++ strings problem...?

Say I have the string





NewYork;NewJersey





I want to put in a string everything up to the point that it reaches a ;





So in this case I would like a string to have NewYork





Can anyone write a small program that will do this?





Thanks in advance!

How do you go about solving this basic C++ strings problem...?
//--------------------------------------...


// StrT: Type of string to be constructed


// Must have char* ctor.


// str: String to be parsed.


// delim: Pointer to delimiter.


// results: Vector of StrT for strings between delimiter.


// empties: Include empty strings in the results.


//------------------------------------...


template%26lt; typename StrT %26gt;


int split(const char* str, const char* delim,


vector%26lt;StrT%26gt;%26amp; results, bool empties = true)


{


char* pstr = const_cast%26lt;char*%26gt;(str);


char* r = NULL;


r = strstr(pstr, delim);


int dlen = strlen(delim);


while( r != NULL )


{


char* cp = new char[(r-pstr)+1];


memcpy(cp, pstr, (r-pstr));


cp[(r-pstr)] = '\0';


if( strlen(cp) %26gt; 0 || empties )


{


StrT s(cp);


results.push_back(s);


}


delete[] cp;


pstr = r + dlen;


r = strstr(pstr, delim);


}


if( strlen(pstr) %26gt; 0 || empties )


{


results.push_back(StrT(pstr));


}


return results.size();


}








Examples:





// using CString


//------------------------------------...


int i = 0;


vector%26lt;CString%26gt; results;


split("a-b-c--d-e-", "-", results);


for( i=0; i %26lt; results.size(); ++i )


{


cout %26lt;%26lt; results[i].GetBuffer(0) %26lt;%26lt; endl;


results[i].ReleaseBuffer();


}





// using std::string


//------------------------------------...


vector%26lt;string%26gt; stdResults;


split("a-b-c--d-e-", "-", stdResults);


for( i=0; i %26lt; stdResults.size(); ++i )


{


cout %26lt;%26lt; stdResults[i].c_str() %26lt;%26lt; endl;


}





// using std::string without empties


//------------------------------------...


stdResults.clear();


split("a-b-c--d-e-", "-", stdResults, false);


for( i=0; i %26lt; stdResults.size(); ++i )


{


cout %26lt;%26lt; stdResults[i].c_str() %26lt;%26lt; endl;


}
Reply:I want to put in a string everything up to the point that it reaches a ;





So in this case I would like a string to have NewYork


????





Your question does not make any sense
Reply:Use the strtok function to tokenize the string around the ;





# include %26lt;iostream%26gt;


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


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





int main (void)


{


char str[ ] = "NewYork;NewJersey;


char *pch;





pch = strtok(str, ";"); //Takes the string str and tokenizes it around the delimiter that was specified.





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





return 0;


}
Reply:i am writing here very simple code segment of basic level that would not take in to consideration complex phenominon involved like memory allocation etc. just for the sake of simplicity


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


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





int main()


{


char YourString[]= "NewYark;NewJersey";


char OutString[100]; //we asume the string is less than 100 characters





int i=0;





while(true) //infitie loop is controlled by a break statement in block


{


if(YourString[i]==0 || YourString[i]==';') //end of string of or a semicolon?


{


OutString[i]=0; //place a string terminator null to out string


break; // and break the loop


}


else


{


OutString[i]=YourString[i];// this character is to be included in outpu string


i++; incres index


}


printf("\nInput String:%s, Output string=%s",YourString,OutString);


getch()


return 0;


}





this will serve your purpose elegantly. But for string, there are many memory allocation problems are involved which I just overlooked for the sake of simplicity and focused on main problem. Hope that answers the questions. If you still have any query, feel free to write at khan10200@yahoo.com





Thanks


C++ help. i need to know the proper syntax of a 'string function'?

C++ has many string functions. Try to read this tutorial anyway:





http://www.cppreference.com/cppstring/in...

daylily

Wat is the C program to display all the palindromes in a given string??

Eg: the word "dadmom" has 2 palindromes..and we should display them

Wat is the C program to display all the palindromes in a given string??
Nested for loops would do it.
Reply:#include%26lt;stdio.h%26gt;


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


void main()


{


char word[80];


int i,j,len,flag=0;


printf("enter a string:");


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


len=strlen(word);


for(i=0,j=len-1;i%26lt;=len/2;i++,j--)


{


if(word[i]==word[j])


flag=1;


else


flag=0;


}


if(flag==1)


printf("given string is palindrome:%s",word);


else


printf("given stringis not apalindrome:%s",word);


}








Output:





Enter a string:


Madam


Given string is palindrome.


Write a C function that counts the number of words in a string.?

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


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





int


main(int argc, char* argv[])


{


  char *token, *string = argv[1];


  int count = 0;





  while ((token=strtok(string, "\t ")) != 0) {


    count++;


    string = 0;


  }


    


  printf("String has %d words\n", count);





  return 0;


}








And to show that it works:





$ cc cw.c





$ a.out "this is a simple test"


String has 5 words

Write a C function that counts the number of words in a string.?
if you're doing this for a class, please learn it and don't ask someone else to do it for you. If you're not taking a class and you just need help with part of a program you're writing then the following information should be enough to help you out:





-use a tokenizer to determine where a word begins and ends


-use a counter within a loop that increases by one every time a new word is found.
Reply:See link


If a string (say "1234") is entered thru the keyboard wap in c(NOT C++) to print the output 1234?

if this program is just to show the string as a number, then u can print it the way a string is printed...... there will be a different case if u need to perform mathematical operations on this string, then u need to typecast the string into int.


for simple way


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


void main()


{


char str[10];


printf("Enter any string\n"):


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


printf("The string is %s",str);


}

If a string (say "1234") is entered thru the keyboard wap in c(NOT C++) to print the output 1234?
sum=0;


while((c=getch())!=EOF)


sum=sum*10+(c-'0');


printf(%d sum)


Seperating digits in a string, so they can be converted to integers in C?

this is what i got so far


int likeness(int user1,int user2)/*NOT FINISHED*/


{


int like=100,x;


char *temp,TEMP[20],Temp[1];


int temp1[20],temp2[20];


strcpy(TEMP,user_data[user1].question...


for(x=0;x%26lt;20;x++)


{


temp=TEMP[x];


temp1[x]=atoi(temp);


}


strcpy(temp,user_data[user2].question...


for(x=0;x%26lt;20;x++)


{


Temp[0]=TEMP[x];


temp2[x]=atoi(temp);


}


for(x=0;x%26lt;20;x++)


{


if(temp1[x]!=temp2[x])


like=like-(abs(temp1[x]-temp2[x]));


}


return like;


}


note: user_data is the database file


temp is temporary varibles

Seperating digits in a string, so they can be converted to integers in C?
I'm not sure I completely understand. So every single digit needs to be a separate integer? For example, if you receive 1932 as input do you want 4 integers...1, 9, 3, 2? If so, it would be something more like:


/*


* This is assuming you don't know the length of the


* input string. If you're sure it's 20 chars, then you


* can use a static array of 20 chars like you did. You


* also wouldn't need to do any freeing, etc.


*/


int likeness(int user1, int user1) {


int like = 100;


int x;


char singleDigit[2];


char *input1 = NULL;


char *input2 = NULL;


int temp1;


int temp2;





input1 = strdup(user_data[user1].q...);


if (!input1) {


/* Memory allocation failure... */


/* You can do something here if you want */


}





input2 = strdup(user_data[user2].q...);


if (!input2) {


/* Memory allocation failure... */


/* You can do something here if you want */


}





/*


* This loop assumes input1 and input2 are


* the same length. You might want to check


* the truth in this, etc. but for now...


*/


for (x = 0; x %26lt; strlen(input1); ++x) {


singleDigit[0] = input1[x];


singleDigit[1] = '\0';





temp1 = atoi(singleDigit);





singleDigit[0] = input2[x];


singleDigit[1] = '\0';





temp2 = atoi(singleDigit);





if (temp1 != temp2) {


like = like - abs(temp1 - temp2);


}


}





/* Free up memory */


if (input1) {


free(input1);


}





if (input2) {


free(input2);


}





return like;


}





I haven't compiled this so it isn't guaranteed to work the way you want. Basically you look ok except you can condense your loops and if you use atoi the way you are, you're going to have problems. The atoi function expects the string parameter to be null-terminated (i.e. you need a '\0' on the end).
Reply:Haven't done C in quite a while. But have you researched the MID$ function, I know you can extract any amount of a string with that command. And I can't believe that C doesn't have that command.

flamingo plant

In C++, how do you write a program that reverses a string?

go to help you will see many examples on that

In C++, how do you write a program that reverses a string?
Why do you keep asking the same question? Twice today? For a routine common in learner texts and help files everywhere?





A general answer: check out open source software code. The Linux utilities code that routine in C and I suppose a C++ variant is rattling around somewhere.





All Linux distributions provide source code for download. Stumble around http://distrowatch.com and discover a convenient source for your source code!





I suppose you realize that Redmond's (Bill Gates') C++ variant is purposely different than the ISO approved C++, but that is another issue.
Reply:The reason you're not getting any real helpful responses is because this sounds like a homework question. I doubt the teacher wants you to use a library function, but for you to create it yourself. Read about char arrays. Should figure it out from there.
Reply:strrev() can be used to reverse a string. You can find more details abt the function in the documentation.
Reply:Reversing the string using the Triple XOR Process





int StringReverse(char* strToReverse)


{


if (NULL==strToReverse)


return -1;





int length=strlen(strToReverse)-1;


if (1==length)


return 1;





for(int index=0; index%26lt;length; index++,length--)


{


strToReverse[index] ^= strToReverse[length];


strToReverse[length] ^= strToReverse[index];


strToReverse[index] ^= strToReverse[length];


}


return 0;


}


In C++, how do you write a program that reverses a string?

For example, "hello" would return "olleh"

In C++, how do you write a program that reverses a string?
#include %26lt;string%26gt;


#include %26lt;iostream%26gt;


//...


char* orig = "hello";


std::string reverse;


for (int i=strlen(orig)-1;i%26gt;=0;i--) reverse += orig[i];


cout %26lt;%26lt; reverse;
Reply:push it onto a stack and pop it off





or push it on then set the stack pointer to the other end, then pop
Reply:Dude, DO YOUR OWN HOMEWORK! If you don't, you are not learning how to be a programmer.


C++... made a program that counts consonants and vowels by checking for vowels. i have the vowels in array...?

I'm make a class program that counts consonants and vowels in a user inputed c-string by checking for vowels. i have a, e, i, o, and u in the array "vowels". But there are 5 errors, each letter saying they're not identified.





What's wrong?

C++... made a program that counts consonants and vowels by checking for vowels. i have the vowels in array...?
Put the characters in single quotation marks when you declare the array.





char vowels[] = {'a', 'e', 'i', 'o', 'u'};





Also, when you go to compile, you will get an error dealing with the functions. You declare them as:





int countcons (char *, char[]);


int countvows (char *, char[]);





and the definitions start as:


int countcons(char *strptr, char vowels)


int countvows(char *strptr, char vowels)





Do you see the difference? You need to make the definitions the same as the declarations. The error you are getting means the declarations are telling the program the functions pass two strings, but it isn't finding the definition of a function with that name that takes to c strings (it is finding a function that takes a c string and a single char). Am I making sense? so try making the definitions something like:


int countcons(char *strptr, char *vowels){...code...}


int countvows(char *strptr, char *vowels){...code...}





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


you could make them


int countcons(char *, char *);





int countcons(char *strptr, char *vowelsptr)





or you could use arrays such as:





int countcons(char *, char []);


int countcons(char *strptr, char vowelsptr[])





You could even mix the two.


They are more or less the same thing. (although, most times char* have a '\0' and individually defined vowels arrays will not unless you put one in with the other individual chars) You define a character array called vowels[]. When you pass vowels as a parameter in your functions, char[] and char* are interchangable because vowels is just the address of the first char in a group of characters.








However, you will still have to change your code. In countcons and countvows, You cannot compare a single char in *strptr to vowels and expect it to compare that one char to every char in the array. you have to do something like


if( *strptr != vowels[0] %26amp;%26amp;


*strptr != vowels[1] %26amp;%26amp;


*strptr != vowels[2] %26amp;%26amp;


*strptr != vowels[3] %26amp;%26amp;


*strptr != vowels[4])


times++;


for countcons. You could still use vowels[0], vowels[1], etc if you pass vowels as a char * instead of a char[].





Am I making sense, or just confusing you more?





-------


Part of your problem with errors in counting deals with case sensitivity and spaces. 'A' is not the same as 'a' and if you check the string "Amanda" against your vowel array, you will only find 2 vowels because your vowel array does not contain 'A' Also when you count consonants by seeing if they are in your vowel array, 'A' will be considered a consonant and so will a space between words.


-------


Glad to help. :) I hope you finish it on time. Let me know if you have any other questions.
Reply:You made me curious. What is the program your bf convinced you to write? Report It

Reply:The first answer isn't too bad. I think I would make it a little smaller and use isalpha() and strchr() would be cleaner.





char *vowels="aeiouAEIUO";





int countvows(char *strptr, vowels)


{


int times = 0;





while(*strptr) {


if(isalpha(*strptr)) { // we know it's a-zA-Z now


if(strchr(vowels,*strptr)) // It's a vowel


times++;


strptr++;


} // if


} // while





consonants would be the same procedure basically , except the if() would be:


if(!strchr(vowels,*strptr)) // It's a consonant


}


C++ Segmentation Fault?

Here is my code:


#include %26lt;iostream%26gt;


using namespace std;





typedef struct {


char* name; /* '\0'-terminated C string */


int num;


} SomeStruct;





void allocSpace(SomeStruct **);





int main ()


{


char * b, q, *r;


SomeStruct **arr;


allocSpace(arr);


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


cout%26lt;%26lt;arr[i]-%26gt;num;


return 0;


}





void allocSpace(SomeStruct **x)


{


x = (SomeStruct**) malloc(sizeof(SomeStruct *) * 5);


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


{


x[i] = new SomeStruct;


x[i]-%26gt;num = i;


cout%26lt;%26lt;x[i]-%26gt;num;


}


}

C++ Segmentation Fault?
Use new not malloc,


if it still does not work, may be you can contact a C++ expert at websites like http://getafrerelnacer.com/

umbrella plant

C++ program that write a function that determines if a string is a palindrome with a loop in a function?

I dont know how to write this program. Can someone help?

C++ program that write a function that determines if a string is a palindrome with a loop in a function?
I ll just give u the logic. if i write, then u cant improve.





step 1 :- take the given string and put it in a character array.


step 2: - run a for loop, starting from length(last letter) of array till u reach first character.


step 3:- store each and every character in another array.


step 4:- come out of loop after reaching the end. check whether both char array are same. if so its palindrome or else its not.


Constructors and C array question in C++?

How can I take a type I've created and initalize it with a C string or character array?





ex:








MyType x("initalize to this char array");








How can I make this legal?





MyType::MyType(char ar[])


:


{


for(int i = 0; i %26lt; (sizeof(ar)/sizeof(ar[0])); ++i){


private_member_array[i] = ar[i];


};





}











So basically,





What would be the parameter in my constructor, to make it legal to pass it char array's in the form of:





MyType("data for my type");





Thanks!

Constructors and C array question in C++?
A working anwer:-





#include %26lt;iostream%26gt;


#include "MyType.h"


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


{


MyType* mt = new MyType("data for my type");


std::cout %26lt;%26lt; char(mt-%26gt;pm_array[0]);


return 0;


}





// header MyType.h


class MyType


{


public:


int pm_array[];


MyType(char ar[]);


};





#include "MyType.h"


MyType::MyType(char ar[])


{


for(int i = 0; i %26lt; (sizeof(ar)/sizeof(ar[0])); ++i)


{


pm_array[i] = ar[i];


}


}
Reply:There are different ways to do it.


First could be use char*. (include string.h)





class MyType {


private:


char *private_str;


public:


MyType();


MyType(char*);


~MyType();


}





MyType::MyType() {


private_str = NULL;


};


MyType::MyType(char* str) {


private_str = new char[strlen(str)];


strcpy(private_str,str);


};


//Helps to free memory on destruction.


MyType::~MyType() {


if (private_str) delete private_str;


};





Another way could be to use string. (include string)





class MyType {


private:


std::string private_str;


public:


MyType(std::string%26amp;);





}





MyType::MyType(std::string %26amp;str) {


private_str = str;


};





I hope this helps!!
Reply:Templates
Reply:The correct argument to the constructor is either a character array (as you did) or a character pointer. If you have a character array, use strcpy to copy from the literal to the array. If you have a pointer, you can use assignment.





See http://c-faq.com/decl/autoaggrinit.html . http://cppreference.com/





Take note that if you use a pointer, you can't modify the string contents. But you can with an array.
Reply:I think you're looking for





MyType::MyType (const char * text)





Note that I strongly recommend to use std::string for the internal storage of the string. Handles the classical zero terminated string issues of overruns, memory allocation, concatenation much more pleasantly that C strings.


How to Convert string "610 8345" into Integer in VB.Net or C#?

Try any of this code


Dim i as integer=Convert.ToInt32("your number as string")


or


Dim i as integer=Val("your number as string")


or


Dim i as integer=CInt("your number as string")

How to Convert string "610 8345" into Integer in VB.Net or C#?
'i noticed a space between the 0 and the 8


Dim String1 As String = "6108345"


Dim IntConvert As Integer





IntConvert = CInt(String1)





if there's a space, you'll have to add this code


Const space As Char = " "c


Dim resultArray As String() = string1.Remove(Val(space))





Hope this helps





R3dm0


C++ strings?

Hey! do you know what is this instruction doing... I mean, the ++ after the string...





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


contadores[texto[i]]++;





THANKS!

C++ strings?
Looks to me like you've got an array called "contadores" which is, if I'm not mistaken, "counters" in Spanish.





texto[i] is going to be the i'th character in the string.


if it's, say, an uppercase A, then the 65 element of contadores will be incremented (have one added to it)





Voy a tratar de traducir estos instrucciones a espanol:


Parece que tiene un array (?) que se llama "contadores"


El valor de texto[i] va a ser la character en posision "i" en el string. Si es "A" entonces el elemento en posision 65 va a ser mejorado por uno.





Hope that helps.





It's really hard for me to talk about programming in Spanish.
Reply:increase the char "contadores" at the postition specified by texto[i], increase only 1 such as from 'a' to 'b'. Just like that.





suggess you trying to see its result by using printf to show what happen before and after this instruction, you'll know how it works.
Reply:The ++ increments whatever is before it, the value in contadores[texto[i]] in this case.
Reply:The ++ in contadores[texto[i]]++ will increment the value that the array contadores holds. If contadores is an array of characters it will increment the value it hold - i.e. if contadores[texto[i]] = 'a', contadores[texto[i]]++ will turn 'a' into 'b'.
Reply:in this for loop, i is being start from 0 and incrementing by one(i++) so it must go to 1 ine next iteretion


but it will jump to 2 not to 1


because in next line( contadores[text[i]]++ ) you are incremneting again so it will skip one step so use i+1 instead of i++in next line.
Reply:so your program will find the frequency of the characters...


ie.,for example if, texto has "sriram" then your countadores will increment the respective (ascii) positions.





as my previous person answered...





thanks

deliver flowers

Convert code from C# to VB?

Namespace yahoo


{


Class Program


{


public static int Main(string[] args)


{


TextHelper textHelper = new TextHelper();


SayHello(textHelper);


char[] output = textHelper.GetHelloArray();


foreach (char c in output)


{


System.Console.WriteLine(c);


}


string outputString = textHelper.HelloWorldProperty;


for (int x = 0; x %26lt; outputString.Length; x++)


{


System.Console.WriteLine(outputString[...


}


System.Console.WriteLine(textHelper.Ge...


System.Console.WriteLine();


int input;


do


{


input = System.Console.Read();


} while (input != textHelper.GetKeyForContine());


ExerciseSwitch(1);


ExerciseSwitch(2);


ExerciseSwitch(3);


ExerciseSwitch(Square(2));


return 0;


}


private static void SayHello(TextHelper textHelper)


{


System.Console.WriteLine(textHelper.He...


}


private static long Square(int x)


{


return x * x;


}


private static void ExerciseSwitch(long y)


{


switch (y)


{


case 1: System.Console.WriteLine("2");


goto case 2;


case 2:


System.Console.WriteLine("1 or 2");

Convert code from C# to VB?
Try this site..





http://converter.telerik.com/





There are a few other sites as well.





Most of them work about 80% correctly and the rest you have to do yourself.





Good Luck


What are the thinnest string gauges i should use to tune to drop c?

i have ernie ball beefy slinky strings right now...they are 11-54 gauge....good enough? or do i need the 13-56?

What are the thinnest string gauges i should use to tune to drop c?
I use 11's for standard tuning. Go for the 13's if you are doing drop C and are a somewhat experienced player. If you are still beginning, then maybe the 11's would be better.


C++ Strings?

I have to take in a a string and scramble it 5 times, using string methods. I have to separate it using 2 radnom num's, and into three parts. It won't execute for some reason. Any help will be appreciated. Here's the code:


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Enter a phrase to shuffle: ";


getline(cin,phrase_input);





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


{


beg = phrase_new.substr(0,random_one);


mid = phrase_new.substr(random_one,random_two - random_one);


endphr = phrase_new.substr(random_two,phr_len - random_two);





shuffled_phrased+= endphr;


shuffled_phrased+= beg;


shuffled_phrased+= mid;





}


cout%26lt;%26lt;shuffled_phrased;

C++ Strings?
first, I assume that somewhere you are copying phrase_input into phrase_new somewhere and just didnt show the code.





second, make sure your random_one and random_two are not greater than the length of the string phrase_new.





third, to loop 5 times, your "for" loop should be "for(int i = 0; i %26lt; 5; i++)"





fourth, you need to copy shuffled_phrased back into phrase_new at the end of your loop, so you can repeat the operations on it again.
Reply:Do you know how to use a debugger?


If not, I suggest you learn.





A debugger will help you to pinpoint a problem to a specific line of code. Learn to step through the code and verify it is doing what it is supposed to be doing.





Learn to use breakpoints and the call stack.


A certaain string on a piano is turned to produce middle C(f=261.63 Hz) by adjusting tension in the string.?

For fixed wavelength, what is the frequency when this tension is doubled?

A certaain string on a piano is turned to produce middle C(f=261.63 Hz) by adjusting tension in the string.?
Frequency is proportional to the square root of tension.


http://en.wikipedia.org/wiki/Pitch_(musi...





f \propto \sqrt{T} and for this case 261.63 \propto \sqrt{T}





So, if the tension is doubled.


f ' \propto \sqrt{2T}





By ratios, 261.63 / f ' = sqrt {T} / sqrt {2T}





f ' = (sqrt {T} / sqrt {2T}) / 261.63

floral bouquets

C++ Strings and Structs!!!!! HELP BASIC C++?

This is my struct:





struct PlayerRecord


{





string playerID;


int playerNum;


int playerPoints;





};





I want to ask the user for the Player name, Players number and Player points save it in the struct and then print out the struct in a table.


I was using cin %26gt;%26gt; for the name but it splits the name when a space is added I want to use getline but dont know how to call it and save it in the struct unless it involves a file. I needhelp also in saving the answers into the struct. Thanks code will be helpful so I can see what to do

C++ Strings and Structs!!!!! HELP BASIC C++?
cin.getline(PlayerRecord.playerID);
Reply:DONT HOLD ME TO THIS





I believe cin is for character in, ie, one, not a string. I think you want to either make an array and make the program get each character looped to fill the entire array, ie, cin fills one, then two then three so on....


More than likely you should just use the stream in commands (i dont know what htey are) to get the entire stream, and then put the characters put into a word as an array. Check out the website below - FANTASTIC website.


Saturday, May 22, 2010

C++ Strings?

Is there a better way to add the word "not" after the word "and" in the string "Pork and Beans"?





void replaceit (string %26amp;str, int pos)


{





str.insert (pos + 3, " not");





cout %26lt;%26lt; str %26lt;%26lt; endl %26lt;%26lt; endl;








return;


}





pos is equal to the position in which the word "and" was found in the string "pork and beans". Instead of pos + 3, how can I make it so that any length word would fit too? pos is equal to 5, btw

C++ Strings?
You can tokenize the string ( using strtok ) and then add the words back to an output stream ( ostringstream ) - while adding, you can insert the word "not".


What is the best brand of 5 string bass guitars to use when tuning into C#?Ineed a 5 str that plays wellin C#?

dude any 5 string bass that doesnt play well isnt worth the money try some out at the local stores and or rent one from them till you get the feel samash.com to look around theres links to the stuff you need an old fender percision is one of my favs and i platy a lead les paul

What is the best brand of 5 string bass guitars to use when tuning into C#?Ineed a 5 str that plays wellin C#?
My personal favorites due to tone are Dean Markley Blue Steel


C++ Strings?

Okay i would like to pull a computer ID from Net View using strings. What i have so far is:





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





char A;





using namespace std;





int main (){


system("net view") = A


string str1( A , 11, 4 );


}


however, I can't seem to store new view as a variable.

C++ Strings?
int main (){


A = system("net view")


string str1( A , 11, 4 );


}





you were having system(netview) get the empty variable A.. flip it around and it should work

dried flowers

Snapped a cello string!?

crap today i was tuneing my cello and my c string snapped right off how the heck do i put it back on!? do i have to buy another string!?

Snapped a cello string!?
There are three places that a string will lose tension. The first is the tuning peg. Sometimes the string will slip loose from the peg if it is not anchored properly. You anchor the string by deliberately crimping it after you stick it through the tiny hole. Then as you wind the string around the peg, you guide the string so that it falls over the crimped portion of the string. The pressure from the tightened string will lock the string in place. If the string came loose from that end, you can easily put the string back, or if you are nervous about it bring it to your teacher to do it for you.





The second area is the Tailpiece. The loop or ball end of the string can wear after several months of playing. With a Cello, this can often be extended out to a year or more, but if you are leaving your strings on for long periods of time you will have other issues. If that is broken, the string should be discarded immediately. I have tied a string to a bead and used it in an emergency situation, but I changed it as soon as I got a new one. The tension of a cello string is such that you don't want to mess around with it. You can get a minor injury if it snaps just right, and you can damage your cello if it is not set up properly.





The third area is anywhere in the middle of the string. Over time, the windings may wear down to where they lose their cohesiveness. This usually happens close to the neck nut, somewhere along the area where the cello is most often played with force (usually in the first or third position) or in the area where the cello is bowed. If the bridge is not seated correctly, the winding may be compromised there as well. When the bridge moves back and forth, or is adjusted frequently, the winding may be torn when the bridge is reseated, especially if the strings are not loosened first. Teachers are nervous about loosening all of the strings because the soundpost may fall down, but it is necessary to loosen them enough to re-seat the bridge properly. In all of the cases, the string is now fit only for model railroad enthusiasts.





Of course, the knowledgeable Cellist always keeps a spare set of strings in that little pouch that should be built into your case. That is part of what it is there for. What if this had happened during a concert? Would you forgo the reward for all of your hard work and dedication simply because you did not think to pack a string? The situation where I retied a string with a bead actually happened during an Honors Orchestra concert and it was not one of my students. The repair got the student through the concert but the teacher (who should have been there) called me the next day asking me why I told his student to replace a string that was obviously not even worn. When I described the situation, the teacher got very quiet and simply said, "I will take care of it immediately!"





If you have to buy a C string it is usually best just to buy a complete set. A and D strings are "Relatively" inexpensive and break four to five times as much as C strings. If the C string breaks, it is usually due to trauma to the instrument (it got bumped or banged) or a clear indication that the strings should all be replaced anyway (unless you just replaced an A or D string) You are also going to find that new strings are brighter and speak better than old strings. Having mismatched strings on your instrument can be problematic for students when it comes to overall balance. Consider buying two sets of strings and putting one in the case for the next emergency. I know this is not the answer you want to hear, but this is a genuine case where it is better to be honest with you than try to butter you up for ten points.
Reply:same as the person before me but if u do not know how to put it back on ask the people in the store for help
Reply:if it has simply unwound itself, you can wind it back using the peg, but if it has snapped (as in, broken off entirely), you definitely need to buy a new string.


How can we get a string & reverse it ? without using pointers & arrays in C / C++?

/*i think its impossible to do without using arrays as string is an array of characters but it is possible to do without using pointers*/


void main()


{





char s[10],b[10];int x,k,i;


clrscr();


printf("enter a string\n");


gets(s);


x=strlen(s);


k=0;


for(i=x;i%26gt;0;i--)


{


b[k]=s[i-1];


k++;


b[k]='\0';


}


printf("the reversed string of %s is %s",s,b);


getch();


}

How can we get a string %26amp; reverse it ? without using pointers %26amp; arrays in C / C++?
Technically this is impossible because a string is a char array in c and an object representing a char array in c++. Therefore you MUST use arrays, and to access an array you need a pointer, consider:





char myArray[3]={0, 0, 0};


myArray[2]=3;





this is eqivelent to:





char myArray[3]=(0, 0, 0);


*(myArray+3)=0;





So to reverse a string use something like this:





string reverse(string str)


{


string result="";


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


{


result+=str[a];


}


return result;


}


I need help with pointers in C++?

Write a function that takes a C string as an input parameter and reverses the string. The function


should use two pointers, 'front' and 'rear'. The 'front' pointer should initially reference the first


character in the string, and the 'rear' pointer should initially reference the last character in the


string. Reverse the string by swapping the characters referenced by 'front' and 'rear', then increment


front to point to the preceding character, and so on, until the entire string is reversed. Write a


main program to test your function on various strings of both even and odd length.


*/


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


using namespace std;





void swap_char(int* pFront, int* pRear);





int main(){


string sentence;


int *pFront, *pRear;


cout %26lt;%26lt; "Type in a sentence of less than 40 characers: \n";


cin %26gt;%26gt; sentence;


swap_char(pFront, pRear);


return 0;


}


void swap_char(int* pFront, int* pRear){


while(pRear %26gt; pFront)


{


string sentence;


char temp;


%26amp;temp =

I need help with pointers in C++?
Some tips:





pFront and pRear should be char*, not int*.





You need to set pFront and pRear to something before calling swap_char. However, the problem statement says swap_char's argument should be a "C string". I assume it wants you to use character array, and not a C++ string object. Inconvenient as that may be, you need this signature:





void swap_char(char * const s);





(i.e., const pointer, non-const data)





You might think you should have this call in main() :


swap_char(sentence.c_str());





That won't work, though, because c_str() returns a const char*, and swap_char needs to modify the character array. You need to declare a character array, then copy the c_str from sentence. Also, there's no need to limit the input to 40 characters, or any length.





So you need something like this:





getline(cin,sentence);


char *line = new char[sentence.length()+1];


memcpy(line,sentence.c_str(),sentence....


swap_char(line);





Why getline instead of cin's operator%26gt;%26gt;, you ask? Try them both, you'll see.





Also, #include %26lt;cstring%26gt; for memcpy. And when you're done, don't forget to: delete [ ] line;





I'll leave the guts of swap_char for you to work out, but this should get you going in the right direction.


Can anyone tell me in C language, the difference between character array and string array?

A character array consists of single characters. A string array consists of groups of characters.

Can anyone tell me in C language, the difference between character array and string array?
you are a real curious boy.





character array= a line of characters. note there is always a null char in every char array.





null char= a "bank" space/char==no actual use =p








string array is a actually the same.


string= line of "something"


array= a specific line of string





hope that helped you =p
Reply:The Character array is group of characters (in their ASCII codes).


They are generally one dimensional.





There is no termination symbol for this.





BUt the string array is group of strings (which is again group of characters)


It is mandatory to have two dimensional array for a string array.





String array is terminated with '\0'
Reply:In C a charachter array is a array storing charachters. A string is a charachter array ending with '\0' character which marks end of string. A charachter array containing 'a', 'b', 'c', 'd', '\0', 'e', 'f', 'g' is a charachter array with 8 charachters, but is a string with 4 charachters as fifth element '\0' marks the end of string.





When you say string array, it can mean a array of pointers each pointing to a string.
Reply:A character array consist of single characters while string array consist of s group of characters.
Reply:A string is a character array.


A string array is an array of strings.

gift baskets

Can someone please help me with a c++ program?

ok i have a program which is supposed to work but doesnt, it doesnt output any of the info that i need it to, all that it outputs is the following 20 times, increasing the number by 1 every time:





Record #0 from readdata:


from SetAll








not sure whats wrong with my code, must have something to do with reading in stuff from file, ill post the parts which probably contain the mistake





void SetAll(string l,string f,string s,string c,string st,string z,string M,string m,int i){


cout%26lt;%26lt;"from SetAll"%26lt;%26lt;l%26lt;%26lt;" "%26lt;%26lt;f%26lt;%26lt;" "%26lt;%26lt;s%26lt;%26lt;" "%26lt;%26lt;c%26lt;%26lt;" "%26lt;%26lt;st%26lt;%26lt;" "%26lt;%26lt;z%26lt;%26lt;" "%26lt;%26lt;M%26lt;%26lt;" "%26lt;%26lt;m%26lt;%26lt;endl;


last=l;first=f;street=s;city=c;state=st;...


}


void label(){


cout%26lt;%26lt;first%26lt;%26lt;" "%26lt;%26lt;last%26lt;%26lt;endl;


cout%26lt;%26lt;street%26lt;%26lt;endl;


cout%26lt;%26lt;city%26lt;%26lt;", "%26lt;%26lt;state%26lt;%26lt;" " %26lt;%26lt; zip %26lt;%26lt; endl %26lt;%26lt; endl;;


}





void print(){

Can someone please help me with a c++ program?
You need to use the debugger, or put cout statements at key places to help you debug. This is the life of a programmer.


How do i calculate the length of the string without using the strlen function in c++?

Loop on every char of the string until you hit '\0'

How do i calculate the length of the string without using the strlen function in c++?
#include%26lt;iostream.h%26gt;


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


void main()


{


int i;


char j[21];//WILL STORE 20 CHARS,LAST CHAR FOR NULL


clrscr();


cout%26lt;%26lt;"\nENTER STRING";


cin.getline(j,21);


i=0;


while(j[i]!=NULL)


i++;


cout%26lt;%26lt;"\nLENGTH OF STRING IS %d"%26lt;%26lt;i;


getch();


}
Reply:Use a loop counter until you reach the end.
Reply:#include%26lt;iostream.h%26gt;


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


void main()


{


char test[ ]="This is a test string";


int i=0;


while(test[ i ]) // The Loop continues till test[ i ] is NOT Null


{


i++; //increments i , also counts character


}


cout%26lt;%26lt;"Length of test string is "%26lt;%26lt;i-1; // i-1 because i is the number including NULL


getch();


}
Reply:tape measure


C++ file open, read words and compare with a string?

tempWord = "Hello";


while (inFile %26gt;%26gt; testString) {


if (strcmp(tempWord, testString) == 0)


cout%26lt;%26lt;"work exists"%26lt;%26lt;endl;


}


testString and tempWord are strings so strcmp would work cause it needs character arrays i think.





i am not using objects because it is a simple program.

C++ file open, read words and compare with a string?
strcmp will fail because its a c library function looking for a c variable (in this case a c string). An easy fix to this is to take any string objects and call the .c_str() method. If both things are Strings however you should just use the == operator.


Need help with my c program?

i need my program to read in a file reverse it then write the file out.


i got the reverse correct but its not working.


my errors are:


n.c:12: warning: passing argument 1 of 'fopen' from incompatible pointer type


n.c:21: warning: passing argument 1 of 'fopen' from incompatible pointer type


n.c:22: warning: passing argument 1 of 'fputs' from incompatible pointer type


n.c:22: error: too few arguments to function 'fputs'





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


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


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


int main() {


char string[256];


char*filename[256];


char*outfilen[256];


char c;


int len;


FILE * infile=0;


FILE * outfile;


infile=fopen(filename,"r");


fgets(string, sizeof string, stdin);


len = (strlen(string) - 1);





printf("Reverse string:\n");


for(; len %26gt;= 0; len--)


printf("%c",string[len]);





printf("\n");


outfile=fopen(outfilen,"w");


fputs(outfile);


fclose(infile);


fclose(outfile);


}

Need help with my c program?
fputs() takes two arguments. You need to pass in "string" as well as the file, like this:





fputs(string, outfile);
Reply:Based on my experience in Java,


I think the cause of the warning is that you defined a pointer for the variable (filename)


which I quite don't understand why..


try do declare it like that : char filename[256]


About the Error:


here is the right format for the function fputs:


int fputs ( const char * str, FILE * stream );


All what you have to do is to provide the string you've defined..something like that :


fputs(string, outfile);





-cheers
Reply:A lot of issues here. This version compiles with gcc.


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


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


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


int main() {


char string[256];


char filename[256];


char outfilen[256];


char c;


int len;


FILE * infile=0;


FILE * outfile;





infile=fopen(filename,"r");


fgets(string, sizeof(string), stdin);


len = (strlen(string) - 1);





printf("Reverse string:\n");


for(; len %26gt;= 0; len--)


printf("%c",string[len]);





printf("\n");


outfile=fopen(outfilen,"w");


fputs(string,outfile);


fclose(infile);


fclose(outfile);


}





Note, the arrays are now arrays of 256, not pointers to arrays of 256.





in fgets, sizeof is a function, which means it on't compile unless you write sizeof(string) not sizeof string.








And of course, you reverse the string to stdout, but not to the outfile. That I haven't done anything about fixing. I wouldn't initialize infile when you declare it, incidently. Since you are going to reassign it it might help keep things straight if you assign it down below in the functions. Keep initializing in declarations to consts. That's just preference.

wedding

Write a programme that find the given string is plain order or not in C language?

????does not make any sense

Write a programme that find the given string is plain order or not in C language?
your gonna have to reword that question..."...given string is plain order or not..." what does that mean?


C++ (palindrome strings?)?

i'm tring to write a program in c++ (with recursive function named test palindrome)to return true if the string is palindrome


else


return false

C++ (palindrome strings?)?
what have you used to learn C++? Because i think that "C++ Programming: Program Design Including Data Structures, Third Edition By: D.S. Malik


is a pretty good book it should explain your problem... What are you using to compile it?
Reply:In addition, look at the string class in the stl libraries. It can really help you with manipulating a string as an array.





Other things to consider:


1) Will punctuation or capitalization screw up your comparisons? look at the tolower and isalpha functions.





2) What do you do about spacing? 'A man, a plan a canal, panama' is a palindrome.


How do I play the chords C, A, G, E, D on a 6 string guitar?

I need to know exactly where to put my fingers and exactly which strings to hold down.

How do I play the chords C, A, G, E, D on a 6 string guitar?
For C: hold down 1st fret on the 2nd from bottom string


For A: hold down 2nd fret on the 3rd from bottom string


For G: open on the 3rd from bottom string


For E: hold down 1st fret on 4th from bottom string


For D: open on the 4th from bottom string


Here's a tab if that didn't make sense


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


--2-----------


--2--0-------


--1--0-------


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


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


The numbers represent the fret which your fingers should be on and the dashes represent the six strings.
Reply:C-------o 3 2 o 1 o





A-------o x 2 2 2 o





G------3 2 o o o 3





E------o 2 1 1 o o





D-----o o o 2 3 2





o = open string





x = muffled string ( just lightly touch it with your thumb)





I cant really do this over the internet,its so hard...ok this is called TAB,or tablature,....the first fret would be a 1,second a 2,third a 3.......get it......make sure you practice alot over and over again on one chord first,making sure you dont "rub" against the other strings till it rings true





I highly recommend you start with a G chord first





I hope your guitar is properly tuned





You will KNOW when you got it cause it will sound clean and GOOD





I better get 10 points for this!!