Monday, May 24, 2010

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.


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.

sweet pea

Why would my gdb debugger show me this error? c++?

Here is the error it gave, in my main program the first line is to just cout%26lt;%26lt; 1; It won't even do that without pausing for a long time then giving me a segmentation fault. Anyways here's the error:





Program received signal SIGSEGV, Segmentation fault.


0xff358948 in std::string::_Alloc_hider::_Alloc_hider (this=0xf9018000,


__dat=0xff385ecc "", __a=@0xffbff710)


at /export/home/jco/gnu-sw/src/gcc-3.3.3/sp...


228 /export/home/jco/gnu-sw/src/gcc-3.3.3/sp... No such file or directory.


in /export/home/jco/gnu-sw/src/gcc-3.3.3/sp...


Current language: auto; currently c++

Why would my gdb debugger show me this error? c++?
Yahoo reformats things in ways that are not optimal for programming discussions.





In any case, even if your stuff can across intact it would be hard to figure out the error from the error messages alone. Just post the relevant code. If you are barfing on something like "cout %26lt;%26lt; 1" then it is likely something crazy.


A ring of 10 cm in diameter is suspended from a point 12 cm vertically above the centre by six equal strings.?

The strings are attached to the circumference of the ring at equal intervals, thus keeping the ring in a horizontal plane. The cosine of the angle between two adjacent string is...


A) 2/sqrt(13);


B) 313/338;


C) 5/sqrt(26);


D) 5 sqrt(651)/338;


Kindly explain your answer...

A ring of 10 cm in diameter is suspended from a point 12 cm vertically above the centre by six equal strings.?
The answer is B).


The 6 strings and the 6 ring chords between every 2 suspension points are edges of a regular hexagonal pyramid with a base edge length of 5 (the inscribed regular hexagon's side length is equal to the radius - half of ring's diameter 10) and altitude 12. The right triangle with legs radius (5) and altitude (12) yields the lateral edge's length of 13 and the cosine law, applied to a lateral face (isosceles triangle with sides 5, 13 and 13) yields the answer:


(13² + 13² - 5²)/(2*13*13) = (338 - 25)/338 = 313/338

bottle palm

Is the Schecter C-5 bass a good five string?

You can get one new for $550, Im gonna try to find one used though.

Is the Schecter C-5 bass a good five string?
my friend has one and it sounds and feels really good...for 550 thats a good deal





AE
Reply:schecter is a very good brand. i got my ex an a-7 elite guitar for his b-day a few years ago.... beautiful guitar. if you can't find a used c-5, then you should def get a new one... it's worth the money .


Using regular expressions in C++?

If you have a string of text





(for example, "1234 quick 1234 brown 1234 fox")





and you wanted to use a regular expression to identify any words in that string of text, what is the c++ code that would do it?





Note: A word is defined as any sequence of letters that is not interrupted by a space.





I could really use an example of code.





What #include statements would I need? Is there a way to do it without including regex? Where do I get regex (if I try to include it now, my compiler gives me an error, so I assume I need to get it from somewhere)?





Please note, I don't need a tutorial on regular expressions. I understand regular expressions well enough as it is, I just need to know how to use them in C++.

Using regular expressions in C++?
well... one way would be to search through the string until you found a space, or CR/LF.





Im not sure what you want to do when you find them but something like this will count them:





char mystring[] = "1234 quick 1234 brown 1234 fox";


int count, words = 0, spaces = 0, crlf = 0;


BOOL wordsstart = 1;





for (count = 0; count %26lt; sizeof(mystring); count++)


{


if (mystring[count] == 0x20) //space


{


spaces++;


wordstart = 1;


}


else if (mystring[count] == 0x0a || mystring[count] == 0x0d) //carriage return or line feed


{


crlf++;


wordstart = 1;


}


else if (wordstart %26amp;%26amp; ((mystring[count] %26gt;= 'a' %26amp;%26amp; mystring[count] %26lt;= 'z') || (mystring[count] %26gt;= 'A' %26amp;%26amp; mystring[count] %26lt;= 'Z')))


{


words++;


wordstart = 0;


}


}





its just off the top of my head, but it should work
Reply:google up pcre





http://www.pcre.org/!


URGENT HELP PLEASE - Rock on Strings?

https://tycho-s.phys.washington.edu/cgi/...





A 540 gm rock is whirled on the end of a string 45 cm long which will break under a tension of 32 N.


a) What is the highest speed the rock can reach before the string breaks? (Neglect gravity.)





vmax = m/s





HELP: Draw a FBD of rock on string.


b) If two other strings identical to the first were attached to the rock, how fast could the rock be whirled before the three strings would break?





v'max = m/s


Next the rock is held by two of the same 45 cm strings with ends 63 cm apart and whirled in a circle between them. Neglect gravity.





c) What is the radius of the circle of motion?





R = cm


d) Now what is the maximum speed the rock can have before the string breaks?





v''max = m/s

URGENT HELP PLEASE - Rock on Strings?
isnt this your homework??
Reply:Aaaahhh... I know watcha up 2 buddy...


Ukulele - alternate tuning - strings?

I just bought a soprano ukulele which I plan to use for playing Indian classical music. I know that the uke is traditionally tuned to GCEA tuning. But, I want to use it with a CGCG (lower C, lower G, middle C, middle G) tuning. This is the most convenient tuning for playing Indian classical music.





I want to purchase strings which would be suitable for this tuning. I tried using La Belle nylon banjo strings which have the required octave range but they are too thin and the quality of sound from the sound box is not as good as the original nylon strings.





I have no idea about what kind of guitar strings are suitable for my purpose and would really appreciate if someone knowledgable about guitar tuning OR uke tuning could help me by suggesting the right strings (brand / product name would really help.) Thanks.

Ukulele - alternate tuning - strings?
I've always heard that it goes MDHF. thats for "My Dog Has Fleas". also i don't think your supposed to use guitarre strings on a ukellele. its supposed to be some sort of twine or something, as opposed to wire... hence the name ukellele.

magnolia

In Visual C++, I want to read a string from a text file, and assign it to a variable?

But for some reason I have programmer's block and am not quite sure of how to do it. I guess that's what happens when you've been looking at code for three days straight, all day long. I have attempted to do so by trying to force myself to think creatively, but my attempt is quite obviously flawed.





For instance, I have a variable called "fullscreen_x". I want this variable to be assigned information from a specific point on a specific line of a text file (like a user configuration file).





Basically, I just want to know how to read information from a text file. Thanks

In Visual C++, I want to read a string from a text file, and assign it to a variable?
Fred: A disgrace how you answer straight away with full code; you are encouraging laziness. Give hints and algorithms and let the asker implement them rather than showing up.





For the asker:


one of many variation to solve your problem would be:


1.) Read the file


2.) store the content into a data structure (vector, list ...etc.)


3.) Implement a search module which will iterate through that data structure


4.) Tokenize the search result and format it


5.) Assign that result to the variable
Reply:I do it somewhere in there.....I'm to lasy to pick it out....its part of fstream...that is how you open a file read from it into a string, then output to a file, this was compiled with GNU though...hope it still helps














big_int_calc.cpp





A program that will read in a large integer from a file then preform calculations on the number. It will then output the result into another file.








*/





#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


#include"big_int.h"


#include"char_to_int.h"





int main(){


//ask the user for options and store as an integer


int option;


std:: cout %26lt;%26lt; '\n'%26lt;%26lt; "Enter an option: " %26lt;%26lt; '\n';


std::cout %26lt;%26lt; "1. Read a big intger from file and add" %26lt;%26lt; '\n';


std::cout %26lt;%26lt; "2. Enter big integer,and multiply by 10^n" %26lt;%26lt; '\n';


std::cout %26lt;%26lt; "3. Multiply an integer read from file" %26lt;%26lt; '\n';


std:: cin %26gt;%26gt; option;





//big int to store result in


big_int result;


//big int to store input data


big_int in_data1, in_data2;





if(option == 1){


//variable to store the file name


char file_name[20];





//ask the user for the name of the file they would like to read from


std:: cout %26lt;%26lt; "Enter the file name you would like to read a big integer from: ";


//input of the file name


std:: cin %26gt;%26gt; file_name;





//opens the file, if file is not opened error is output


std::ifstream in;


in.open(file_name);





// outputs error if needed


if(!in){


std::cout%26lt;%26lt; "Error cannot open file" %26lt;%26lt; '\n';


};





//read the data from the file into a C-array that is a member of the class big_int











int index = 0; // variable to try and make the array size itself


bool second_num = false; // variable to declare when to start second number input


int i = 0; //i is used as the index, but is also the size of the array for in_data1


while(!in.eof()){


char temp;


in.get(temp); // stores the value of the char read in into temp





if(temp != '\n' %26amp;%26amp; temp != '+'){ //filters new line char and +





if(temp == ';'){ // checks for the second number





second_num = true; //sets the value of second num to true once ; is read


// the size of the first big int will be i -1


i = 0; // resets the index


};


//reads first number


if(second_num == false){


in_data1.num_array[i] = char_to_int(temp); //stores value as integer in big_int data type


++i;


in_data1.set_array_size(i); // sets the size of the array


};





//reads in second number with filters


if(second_num == true %26amp;%26amp; temp != ';'){ //filters out ; that may be at the end of the file


in_data2.num_array[i] = char_to_int(temp); //stores the value as an integer in big_int


++i;


in_data2.set_array_size(i); // sets the value of the array size


};


};


};





// variable that decides if user wants to output to screen or file


int result_option;


if(option == 1){


//calculates result


result = in_data1 + in_data2;


//ask user for the input of the option


std::cout%26lt;%26lt; '\n' %26lt;%26lt; "To output result to screen enter 1, to output to file enter 2: ";


std:: cin %26gt;%26gt; result_option;


result = in_data1 + in_data2;


if(result_option == 1){


std::cout %26lt;%26lt; "The result is: " %26lt;%26lt; '\n';


result.output();


std::cout %26lt;%26lt; '\n';


};





};





// outputs to file if option is 2


if(result_option == 2){


//calculates result


result = in_data1 + in_data2;


//ask the user the name of file to write to


std::cout %26lt;%26lt; "Enter the file name to write to: " %26lt;%26lt; '\n';


char outfile_name[20];


//declares the file to be written to


std::cin %26gt;%26gt;outfile_name;


std::ofstream outfile(outfile_name, std::ios::app);





// format output


outfile %26lt;%26lt; "The result is: " %26lt;%26lt; '\n';


for(int i = 0; i %26lt; result.size(); ++i){


outfile %26lt;%26lt; result.num_array[i];


if( i % 50 == 0 %26amp;%26amp; i %26gt; 0){ //starts new line every 50 char


outfile %26lt;%26lt; '\n';


};





};


// output of ; at end of file


outfile %26lt;%26lt; ';';











};


};





// declares a big int entered int which is entered by the user


big_int entered_int;


if(option == 2){


//ask the user what they would like to do with the result


int output_option;


std::cout %26lt;%26lt; "To output to screen enter 1, to output to file enter 2: ";


std::cin %26gt;%26gt;output_option;


char temp;


char int_in[500];





//inputs the big integer to the big_int class array


int index = 0;


std::cout %26lt;%26lt; "Enter big integer with e to end input: " %26lt;%26lt; '\n';


//uses sential value to end input


while(std::cin%26gt;%26gt; temp){


if(temp == 'e'){


break;


};


//converts the char to integers


entered_int.num_array[index] = char_to_int(temp);


++index;


};


//inputs the value of n


entered_int.set_array_size(index);


std::cout %26lt;%26lt; "Enter n (10^n) n=";


int n;


std::cin%26gt;%26gt; n;


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


//adds 0's on the end of the array


entered_int.num_array[entered_int.size()... = 0;


};


// sets new array size


entered_int.set_array_size(entered_int.s... + n);


if(output_option == 1){


std::cout %26lt;%26lt; "The result is: " %26lt;%26lt; '\n';


entered_int.output();


};





if(output_option == 2){


//writes to file if user chooses that optioin


std::cout %26lt;%26lt; "Enter the file name to write to: " %26lt;%26lt; '\n';


char outfile_name[20];


std::cin %26gt;%26gt;outfile_name;


std::ofstream outfile(outfile_name, std::ios::app);





//formats output with 50 char per line


outfile %26lt;%26lt; "The result is: " %26lt;%26lt; '\n';


for(int i = 0; i %26lt; entered_int.size(); ++i){


outfile %26lt;%26lt; entered_int.num_array[i];


if( i % 50 == 0 %26amp;%26amp; i %26gt; 0){


outfile %26lt;%26lt; '\n';


};





};


//adds ; at end of file


outfile %26lt;%26lt; ';';











};


};











// variable that decides if user wants to output to screen or file


int result_option;


if(option == 3){


//variable to store the file name


char file_name[20];





//ask the user for the name of the file they would like to read from


std:: cout %26lt;%26lt; "Enter the file name you would like to read a big integer from: ";


//input of the file name


std:: cin %26gt;%26gt; file_name;





//opens the file, if file is not opened error is output


std::ifstream in;


in.open(file_name);





// outputs error if needed


if(!in){


std::cout%26lt;%26lt; "Error cannot open file" %26lt;%26lt; '\n';


};





//read the data from the file into a C-array that is a member of the class big_int











int index = 0; // variable to try and make the array size itself


bool second_num = false; // variable to declare when to start second number input


int i = 0; //i is used as the index, but is also the size of the array for in_data1


while(!in.eof()){


char temp;


in.get(temp); // stores the value of the char read in into temp





if(temp != '\n' %26amp;%26amp; temp != '+'){ //filters new line char and +





if(temp == ';'){ // checks for the second number





second_num = true; //sets the value of second num to true once ; is read


// the size of the first big int will be i -1


i = 0; // resets the index


};


//reads first number


if(second_num == false){


in_data1.num_array[i] = char_to_int(temp); //stores value as integer in big_int data type


++i;


in_data1.set_array_size(i); // sets the size of the array


};





//reads in second number with filters


if(second_num == true %26amp;%26amp; temp != ';'){ //filters out ; that may be at the end of the file


in_data2.num_array[i] = char_to_int(temp); //stores the value as an integer in big_int


++i;


in_data2.set_array_size(i); // sets the value of the array size


};


};


};





//calculates result


result = in_data1 * in_data2;


//ask user for the input of the option


std::cout%26lt;%26lt; '\n' %26lt;%26lt; "To output result to screen enter 1, to output to file enter 2: ";


std:: cin %26gt;%26gt; result_option;


if(result_option == 1){


std::cout %26lt;%26lt; "The result is: " %26lt;%26lt; '\n';


result.output();


std::cout %26lt;%26lt; '\n';


};





};





// outputs to file if option is 2


if(result_option == 2){


//calculates result


result = in_data1 + in_data2;


//ask the user the name of file to write to


std::cout %26lt;%26lt; "Enter the file name to write to: " %26lt;%26lt; '\n';


char outfile_name[20];


//declares the file to be written to


std::cin %26gt;%26gt;outfile_name;


std::ofstream outfile(outfile_name, std::ios::app);





// format output


outfile %26lt;%26lt; "The result is: " %26lt;%26lt; '\n';


for(int i = 0; i %26lt; result.size(); ++i){


outfile %26lt;%26lt; result.num_array[i];


if( i % 50 == 0 %26amp;%26amp; i %26gt; 0){ //starts new line every 50 char


outfile %26lt;%26lt; '\n';


};





};


// output of ; at end of file


outfile %26lt;%26lt; ';';











};








/*


if(option == 4){


std::cout %26lt;%26lt; "Input a number to calculate the factorial of: ";


int fact_in;


std::cin %26gt;%26gt; fact_in;


big_int result;


result = fact(fact_in);


std::cout %26lt;%26lt; '\n' %26lt;%26lt; "Enter 1 to output to screen, enter 2 to output to file: " ;


int result_option;


std:: cin %26gt;%26gt; result_option;


if(result_option == 1){


result.output();





};


// outputs to file if option is 2


if(result_option == 2){





//ask the user the name of file to write to


std::cout %26lt;%26lt; "Enter the file name to write to: " %26lt;%26lt; '\n';


char outfile_name[20];


//declares the file to be written to


std::cin %26gt;%26gt;outfile_name;


std::ofstream outfile(outfile_name, std::ios::app);





// format output


outfile %26lt;%26lt; "The result is: " %26lt;%26lt; '\n';


for(int i = 0; i %26lt; result.size(); ++i){


outfile %26lt;%26lt; result.num_array[i];


if( i % 50 == 0 %26amp;%26amp; i %26gt; 0){ //starts new line every 50 char


outfile %26lt;%26lt; '\n';


};





};


// output of ; at end of file


outfile %26lt;%26lt; ';';








};


};


*/





return 0;


};


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.


Help plz using c?

this program reverses the string entered by input from the user.





int main() {


char string[256];


int len;


fgets(file, 256-1, stdin);


len = (strlen(string) - 1);


printf("You entered %s \nlength %d:\n", file, len);


printf("Reverse string:");


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


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


printf("\n");


}


i need to do this


You will read in a file supplied from the commandline (filename.ext,) and write/overwrite out a file which will be called (filename.ext.mng.)





This file will be essentially the same as the original file, but will have all characters on all lines the reverse of the original. For example:


The original file has:


Jack Spratt


could eat no fat.


His wife


could eat no lean.


The output file will look like:


ttartpS kcaJ


.taf on tae dluoc


efiw siH


.nael on tae dluoc

Help plz using c?
Take out the printf's ("You entered %s....." and "Reverse string...").





Take out the printf("\n"); at the end of the loop.





Then just do it from the command line:





myprog %26lt;filename.ext %26gt;filename.ext.mng
Reply:your reverse program dosen't seem to be working


here is a program that works:


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





void reverse( const char * const sPtr );





int main(){


char sentence[ 80 ];





printf( "Enter a line of text:\n" );


gets( sentence );





printf( "\nThe line printed backwards is:\n" );


reverse( sentence );


}





void reverse( const char * const sPtr ){


if( sPtr[ 0 ] == '\0' ){


return;


}


else{


reverse( %26amp;sPtr[ 1 ] );





putchar( sPtr[ 0 ] );


}


}


Waves and strings?

In figure 16-38a, string 1 has a linear density of 3.70 g/m, and string 2 has a linear density of 7.10 g/m. They are under tension due to the hanging block of mass M = 351 g. Calculate the wave speed on (a) string 1 and (b) string 2. (Hint: When a string loops halfway around a pulley, it pulls on the pulley with a net force that is twice the tension in the string.) Next the block is divided into two blocks (with M1 + M2 = M) and the apparatus is rearranged as shown in figure 16-38b. Find (c) M1 and (d) M2 (in grams) such that the wave speeds in the two strings are equal.


http://s95.photobucket.com/albums/l156/p...

Waves and strings?
d1 = 3.70 g/m = 3.70x10^-3 kg/m


d2 = 7.10 g/m = 7.10x10^-3 kg/m


M = 351g = 0.351kg


the total tension is Mg and this is shared between both strings evenly so there is a tension of


T = Mg/2


in each string


then


v = √(T/d) = √(Mg/(2d))


plug d1 and d2 in this to find v1 and v2 respectively, gives


a) v1 = 21.6m/s


b) v2 = 15.6m/s





M = M1 + M2


the tension in each string is


T1 = M1g %26amp; T2 = M2g


in this case you have


v1 = √(T1/d1) = √(M1g/d1)


%26amp;


v2 = √(T2/d2) = √(M2g/d2)


so for the velocities to be equal you need


√(M1g/d1) = √(M2g/d2)


M1/d1 = M2/d2


so substitute M2 = M1d2/d1 in


M = M1 + M2 = M1( 1 + d2/d1)


gives


c) M1 = M / ( 1 + d2/d1) = Md1/(d1 + d2) ≈ 0.120kg = 120g


substitute this in


M2 = M1d2/d1


gives


d) M2 = Md2/(d1 + d2) ≈ 0.231kg = 231g





...........
Reply:Let attachments take care of themselves, just stay away!

forsythia

In Winapi (Visual C++) , how do i get a string "EQ1" from my string list into my resource box "QUESTIONBOX" ?

My current code is:





SetDlgItemText (hwnd, QUESTIONBOX, EQ1)





It returns an error, saying that it cannot convert from const int to const char :S





Hmm wat if i use SetWindowText..


Could someone paste in the exact code i need to type to make this work. thanks.

In Winapi (Visual C++) , how do i get a string "EQ1" from my string list into my resource box "QUESTIONBOX" ?
The following link from Microsoft shows an example on


how to use "SetDlgItemText"





http://msdn.microsoft.com/library/defaul...





SetDlgItemText(hDlg, IDS_POS, Roster[i].tchPosition);





May be this can help you


C programe that can transger a string "Hello", to another connected computer. after receving "Hello, the rece

Your question is quite confusing! Can you rephrase your question?

C programe that can transger a string "Hello", to another connected computer. after receving "Hello, the rece
Are you talking about a C++ program ? Your question is confusing. However, you need to network two computers so that the C++ compiler can communicate with the other C++ compiler. You need to find out how to network computers


C program, use recursive method find string length?

why do I get the feeling that this sounds like a homework assignment? I am giving a very small code that demonstrates the principle. I absolutely will not recommend something like this for any form of deployment





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





int findlen(char * s) {


int len;


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


return 0;


}


len = findlen(s+1);


return len+1;


}





int main() {


char str[25]="hello world test";


int len = findlen(str);


printf("length = %d\n", len);


}

C program, use recursive method find string length?
U will find the code here:


http://www.codeguru.com/forum/showthread...
Reply:Strings in c are represented as some series of ascii characters followed by the NULL ascii character (represented numerically as 0). So, to do it recursively, our else case increments some variable (the length of the string) while our base case checks to see if the current location in the string is 0 or not. If so, we are done.





//assume we have the value at pointer length is initialized to 0


char strlen (char* s, int* length) {


if (!*s) {


return;


}


else{


*length++;


strlen(s++,length);


}


}





It could be written more efficiently, but you get the idea.
Reply:See here, you may find the answer: http://www.codeproject.com


C program to print a particular string for hundred times without any condition statements?

The following program would do the trick.


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





int c=101;


int f()


{


c=c-1;


c %26amp;%26amp; printf ("The string \t") %26amp;%26amp; f();


return 1;


}


void main()


{f();}





Hope this solves your problem.


-Regards, Rahul

C program to print a particular string for hundred times without any condition statements?
No conditional statements doesn not mean no loops ;)


FOR loop dude!


for (int i=0; i%26lt;399;i++)
Reply:Thats a stupid question. The only solution is to type printf("string"); 400 times.





You get no benefit. Use a damn for loop.
Reply:write this line hundred times


printf("Your string...");

jasmine

C program to find wheather the string is palindrome or not..friends please help!!?

we can do this using the string functions





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


main()


{


char a[20],b[20];


printf("enter a string");


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


strcpy(b,a);//copies string a to b


strrev(b);//reverses string b


if(strcmp(a,b)==0)//compares if the original and reverse strings are same


printf("\n%s is a palindrome",a);


else


printf("\n%s is not a palindrome",a);


return 0;


}

C program to find wheather the string is palindrome or not..friends please help!!?
Hey thats an excellent trick of finding whether palindrome or not. Good. Keep going..... Report It

Reply:palindrome: It is a word, phrase, number or other sequence of units that has the property of reading the same in either direction.for example:"madam",it can be read in both the directions..


void main()


{


//first read a string A from the key-board using scanf().


// now reverse the given string and store the


//resultant in string C.compare strings A and C using string


//handling functions "strcmp".if it is true then print that string is


//palindrome else print that the string is not palindrome


}


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

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





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

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





char buf[32];


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





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





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


int yo = 12345;


char buf[30];


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





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





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


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


How do i convert numbers in string format to int in c#?

int x = int.Parse("123");

How do i convert numbers in string format to int in c#?
You would use the Int32.Parse() method; however, this method will throw an exception if the string that is passed to it is not a valid sequence of characters that defines an integer.





One thing I like to do (and this method can be overloaded since it differs by parameter type as well as return type) is to take a string and an second parameter as a default value if it fails. You would then have something like:





int GetValue(string data, int defaultValue)


{


int result = defaultValue;





try { result = Int32.Parse(data); }


catch { }





return result;


}
Reply:Something like this should work for you





public int convertStringToInt(string strSource)


{


try


{


return int.Parse(strSource);


}


catch


{


return null;


}





}


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.

crab apple

How to input a binary string bit by bit in C?

input a string array in the same way u do for integers.


char arr[20];


for(int a=0;a%26lt;=20;a++)


{


scanf("%c",%26amp;arr[a]);


}

How to input a binary string bit by bit in C?
Strait C? Not C++... boy it's been a long time!





I would recommend storing the values in a char array and then converting the result after it was all input.





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


char line[100];


printf("Enter Binay String");


fgets(line, sizeof(line), stdin);
Reply:Use cin in a for loop?
Reply:/* this code will promt u to enter d string until u press ENTER key.....





char ch;


char string[100];


int i=0;





while( ch != 13) // 13 is ascii value for "enter" or carriage return..


{


ch = getchar();


string[i]=ch;


i++;


}


Will certain gauge strings warp my guitars neck?

I've had my B.C. Rich NJ Series Beast for about 4 years now, and it's been through alot. The only reason I haven't bought a new one is because nothing I play is as good as the beast: Playability, sound, looks, the whole thing. And since it's been through hell, i don't know if it's slowly being destroyed. I've used so many strings, different tunings, gauges, brands, and after looking for so long, I've found the best, Jim Dunlop 10-52's, tuned to C#, F#, B, E, G#, C#. Is this a bad thing? I'm just paranoid that the strings in that tuning will mess up the guitar.

Will certain gauge strings warp my guitars neck?
Yeah that is another myth I gonna bust for ya. No different gauge string will not warp your neck. As you said it has been thru alot and Ill bet you from just setting it down and propping it against the wall has had more effect on it. True the thicker gauge wire you use the more tension can be built up, but again your string is what is getting the worse for wear. Mos guitars are used for 40 hrs of play before you get a new string too so just as apoint of fact is there is always suppose to be tension.


However if you still don't want to chance it, then everytime your not playing it unstring it and restring and tune when you do want to play it.
Reply:Those strings, tuned that low on a B.C. Rich should put very little strain on your guitar's neck. I've used 11s and 12s on my guitars, tuned 1 1/2 steps higher for years without any problems.
Reply:nah


theres rumors going around like that.


your neck will be perfectly fine my friend.





im proud to see a fello guitarist take worry in his guitar.


How do i put a string into an array in c language?

declare it as an array

How do i put a string into an array in c language?
create a character array and copy the string into the array?


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

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





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





string s = "";





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





//now to search for a word use





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





Regards,

strawberry

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!!


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


I need to create a C++ program which will analyze a sentence written in the code and print the longest words?

Say the sentence was "There's the spoons pass me one" I would like the program to print both "There's" as its the longest word with an " ' " and "spoons" because its the longest word.





I am trying to work it out using strings and arrays.





Im using Visuall Studio 2005 c++.





Also how can I get the program to tell me how many of 1 letter is in the whole sentence.

I need to create a C++ program which will analyze a sentence written in the code and print the longest words?
Here is a gift.





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;vector%26gt;





using namespace std;





int findLetter(const string%26amp; str, const char letter)


{


size_t pos = 0;


int count = 0;





do


{


pos = str.find(letter, pos);


if (pos != string::npos)


{


count++;


pos++;


}





} while (pos != string::npos);





return(count);


}








void parseWords(vector%26lt;string%26gt; %26amp;a, string str)


{


size_t pos = 0;


size_t start = 0;


string tempStr;





do


{


pos = str.find(' ', start);


if (pos != string::npos)


{


tempStr = str.substr(start, pos - start);


pos++;


start = pos;


}


else


{


if (start != string::npos)


{


tempStr = str.substr(start);


}


}





a.push_back(tempStr);





} while (pos != string::npos);





}














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


{


const string sentence("There's the spoons pass me one");





char letter;





//find requested letter





cout %26lt;%26lt; "Enter letter to find in sentence: ";


cin %26gt;%26gt; letter;


cout %26lt;%26lt; letter %26lt;%26lt; " occurs: " %26lt;%26lt; findLetter(sentence, letter) %26lt;%26lt; " times." %26lt;%26lt; endl;





//load array of words in sentence





vector%26lt;string%26gt; array;





parseWords(array, sentence);





//find longest word





int largestSize = 0;


string largestStr;





vector%26lt;string%26gt;::iterator pos = array.begin();


vector%26lt;string%26gt;::iterator end = array.end();





for (; pos != end; ++pos)


{


if (pos-%26gt;length() %26gt; largestSize)


{


largestSize = pos-%26gt;length();


largestStr = *pos;


}


}





cout %26lt;%26lt; "Largest word was \"" %26lt;%26lt; largestStr %26lt;%26lt; "\" with a size of " %26lt;%26lt; largestSize %26lt;%26lt; endl;


}
Reply:the one letter of each is easy store the string in an array and go through it letter by letter until you reach the end, have a switch set up example





get the letter put in x





switch (x)





case (a) :





case (b) :








for the first part count letters until white space, store location thats longest somewhere, index through whole sentense if longer replace if not stay the same at the end have a pointer pointing to the beginning of the longest word and print it out or whatever








should get you started think correctly


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);

kudzu

What happens when one of my strings on my piano snaps?

i have a sorta old piano, from london called a metzler....ive got a thingy to tighten the strings but im scared it might snap, its only one string that i need to bring up (first E flat above middle C) and i was just wondering, what happens if a string snaps on the piano? any dangers...to myself....to the piano?








(i might call the tuner ....)

What happens when one of my strings on my piano snaps?
When even just a single string on a piano snaps it alters the tension on the frame and therefore all the other strings, even if only slightly. The result is that you have a piano which is slightly out of tune. Leave it without any attention for any length of time and it will strain the frame, putting it further out of tune. Leave it even longer and not only are you in for a re-stringing job you're in for a major re-tuning job if not a major service. Even doing a single new string will require more than one tuning as it will stretch over a short period of time and need tightening after it's settled.


The moral of this story is this: Get it tuned (which will include re-stringing as necessary) by a qualified piano tuner - and start saving: A visit from a good tuner just to re-tune will cost you in the region of £50 in London, and it's a false economy to try it yourself, even if you've got "a thingy to tighten the strings..."


By the time it's all done 'though, you've got yourself a nice musical instrument which you will enjoy playing.
Reply:I play guitar and a string breaks sometimes
Reply:I'm guessing here but it would probably go "TWANG!!!!"
Reply:If it's an old one, better get a tuner. A snapped string can be replaced, but... it doesn't sound just like the rest even if the whole piano is re-tuned.
Reply:when it snaps, you need to get it fixed.
Reply:None of the notes on your piano, except the very lowest, are sounded by a single string. They all sound by two (middle registers) or three strings (upper registers).





The strings are each set at the top by anchor to a tuning key, then pass through an anchoring stud at the other end. So two strings are physically the same string.





In some cases the "two" strings for a particular note are physically the same string. If you break one of these the particular note will not sound.





In some cases two of three strings for a particular note are physically the same string. If you break one of these you still have one sounding- so you would get a very weak sound.





Up and down your soundboard you will find some string is tuned to one pitch left of the stud and to the half step higher on the other side of the stud. If this string breaks, you will likely have another string to sound the note that you strike, but the sound will be weaker.





Trying not to be too technical --


But you probably really do want to call the piano tuner. It costs to tune a piano, but the costs and trouble of replacing broken strings is probably more painful.





As to your second Question: If the string snaps, and swings - as it might since it is under tension. It could cause some pain and scarring if it hits you. If you have any doubt wear goggles and other face protection.





If you have the tuning key, and you are accomplished musician enough to hear the pitch accurately so as to not overtighten the string - you might pull it off - but generally speaking - "Call The Piano Tuner" - is the best advice for everyone.
Reply:You play out of tune !!!
Reply:ur piano wont be as good
Reply:Call the piano tuner and tell him that the string needs tightening
Reply:if it snaps that key will not work





you can replace that string after it breaks





shouldn't have any other problems


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.


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.


Question about visual c++?

I made a regular DLL by Visual C++ 6 and some functions in it returns a CString object. but when i link it dynamically to a Visual C++ .Net program it receives the string completely wrong , i don't know why, please help me , what i can do to repair this broblem

Question about visual c++?
I'd have to see the code to be sure, but I suspect the problem is that the string you are returning is allocated from within the DLL. If you do this, when the stack frame of the DLL is released the memory is tossed, and becomes random.





If this is the problem, there are 2 ways to deal with it. One is to pass a pointer to a sufficiently large object in the call of the utility function and fill the result into that. The other is to use alloc() to allocate the memory explicitly in the DLL, and then explicitly release it when you are done with it.
Reply:To clarify, I think the string is *staticly* allocated inside the DLL. Of course if it dynamically allocated (through malloc()) there would not be a problem. Report It


garland flower

Guitar tab help: How do I play this while muting these strings?

Here's the tab:





http://www.ultimate-guitar.com/tabs/b/bl...





Ok, the person the wrote it mistakenly put the wrong tuning, he says it's in "Open D" (DGDGBd), but I'm pretty sure that's Open G tuning. But the tuning isn't the issue.





Here's the first riff


d|-0----0-----------------0-----------...


b|-1h3-1-----------------1--3---------...


g|-------3--0-----0--3----------3-----...


d|-------0--0--3-----0----------0-----...


b|-0----0---------------------------0-...


d|------------------------------------...





Ok, so how am I supposed to hammer on 1 to 3 (C to D) while playing the 5th and 1st string open AND muting the 3rd and 4th strings. I'd appreciate it if someone would help me out.

Guitar tab help: How do I play this while muting these strings?
Don't use a pick, fingerpick instead.


Creating an array of strings from a text document?

i am working on a C++ program that requires me to create an array of strings with at least 100 strings. all of which must be pulled from a text document. i can open the document in the program but i do not know how to place the strings into an array. please help.


pseudo-code, or real code will be helpful lol


thanks

Creating an array of strings from a text document?
#include %26lt;iostream.h%26gt;


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


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





int main()


{


int n;





ifstream d;


d.open("datafile.dat");





if (d)


{


d%26gt;%26gt;n;





while(!d.eof())


{


n++;


d%26gt;%26gt;n;





}








}


d.close();


string s[n];


d.open("datafile.dat");


int i=0;


if(d){ d%26gt;%26gt;s[i];


i++;


while(!d.eof()){


d%26gt;%26gt;s[i];


i++;


}


}


return 0;


}
Reply:Here is some code for you, fully commented and very compact, easy to understand variable names as well.





#include %26lt;iostream%26gt; //for basic console io


#include %26lt;fstream%26gt; //for file io


#include %26lt;string%26gt; //for string type


#include %26lt;cassert%26gt; //for assert()


using namespace std;





int main() {


///////////////////VARIABLE DECLARATIONS////////////////////////


ifstream infile; //variable for input of file;


/**/ infile.open("theFile.txt"); //associates file with variable


/**/ assert(!infile.fail()); //makes sure that infile has opened


string array[99]; //the array with only 100 reserved spaces


string holder; //a holder string for use with getline()


int i;





////////////////WHILE LOOP, READS FILE INTO ARRAY//////////


while(!infile.eof()) { //while its not end of infile file


getline(infile, holder); //gets line from infile stores into holder


array[i] = holder; //stores holder in array[i] where i=subscript


i = i + 1; //increments i by 1, allows use of next subscript


}





///////////////FOR LOOP OUTPUTS DATA TO SCREEN/////////


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


cout %26lt;%26lt; array[i] %26lt;%26lt; endl;


}





return 0;


}


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.


 


 


 


C++ program to check whether the string is palindromic or not?

please check the code for a question "Write a program to check whether the given string is palindromic or not."


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


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





void main


{ char x[100];


char y[100];


int temp1,temp2;


int ans = 0;


cout %26lt;%26lt; "Enter the word ";


cin %26gt;%26gt; x;


cout %26lt;%26lt; "Enter the word ";


cin %26gt;%26gt; y;


temp1 = strlen(x);


temp2 = strlen(y);


for(int k = 0;k %26lt; temp1 ;k--)


{for(int j = temp2;j %26lt;= ......;j--)


{if(x[k] == j[k])


ans = 1;


continue;


else


ans = 0;


}}


if(ans == 1)


cout %26lt;%26lt; "The string is palindromic";


else


cout %26lt;%26lt; "The string is not palindromic";


getch();


}


please make the necessary corretions as i dont have a compiler please help!!!!!!!!

C++ program to check whether the string is palindromic or not?
#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





int main()


{


char str[100];





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


cin %26gt;%26gt; str;


int x = strlen(str)-1;


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


{


if (str[i] == str[x-i])


{


continue;


}


else


{


cout%26lt;%26lt;"Not a palidrome"%26lt;%26lt;endl;


return 0;


}


}





cout %26lt;%26lt; "Indeed Palidrome"%26lt;%26lt;endl;


return 0;


}
Reply:Your code is messed up and I don't really understand your logic, if you want to chec whether a string is palindromic, you need only enter one string, not 2.





if it helps, this is how I'd do it, although it is written in C, you should not have much trouble understanding it, specially if you use google.








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


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


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





void trimSpaces(char *buffer);





int main()


{


char buffer[1024];


int start_ctr, end_ctr;


int is_pal;





fgets(buffer, 1023, stdin);


trimSpaces(buffer);





printf("After trim: %s\n", buffer);





end_ctr = strlen(buffer) - 1;


start_ctr = 0;


is_pal = 1;





while( (start_ctr != end_ctr) %26amp;%26amp; (end_ctr %26gt; start_ctr) )


{


if( tolower(buffer[start_ctr]) != tolower(buffer[end_ctr]) )


{


is_pal = 0;


break;


}


start_ctr++;


end_ctr--;


}





if( is_pal )


{


printf("Palindromic, indeed :)\n");


}


else


{


printf("Not palindromic :(\n");


}





return 0;


}





void trimSpaces(char *buffer)


{


int i = 0, j = 0;





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


{


if( isalpha(buffer[i]) )


{


buffer[j] = buffer[i];


j++;


}


}





buffer[j] = '\0';


}








Anobody besides me thinks yahoo needs a CODE tag?
Reply:Hi I study in DPS Ahmedabad if you know me please contact me(i will give you the compiler). This Pogramme will definately work for palindrome check


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


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


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


void main()


{


clrscr();


char x[100];


char y[100];


int temp1,temp2=0;


cout %26lt;%26lt; "Enter the word ";


cin %26gt;%26gt; x;


temp1 = strlen(x)-1;


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


{


y[j] = x[temp1 - j];


}


y[j] = '\0';


x[j] = '\0';


for(int k =0; k%26lt;strlen(x); k++)


{


if (x[k]==y[k]){


temp2 = temp2 + 1;


}


}


if (strlen(x) == temp2)


{cout%26lt;%26lt;"Palindrome";


}


else


{cout%26lt;%26lt;"not a palindrome";


}


getch();


}

blazing star

Help! C++ Question?

How do I remove a blank space in C++? For example, I am reading a bunch of strings from a file, but they all end up as:


" example". How do I remove the blank space from the beginning of the string? Do I have to input blank space before I read and store the string?

Help! C++ Question?
string s = " example";


....


const char* c = s.c_str();


while (*c == ' ' ) c++;


s = c;


...





This will work even if the string has more than one space in the beginning or doesn't start with a space.
Reply:string s = " example";





s[0] = "";
Reply:You might need to filter the input to the string using one of the classes such as getline.


Bass strings for metal... dropped tuning?

Ey there, I'm switching over to bass from guitar (been playing 6 years) for a band I just joined. I'm gonna switch the strings from the bass I just ordered (Dean Z Metalman) since I haven't heard very good reviews for them, and would rather get something other than the stock ones they'll have anyways.





So I'm wondering what strings would be best for playing metal in drop C tuning. So far what I've been recommended are D'Addario, DR, and Ernie Ball.





I love Ernie Ball and Dean Markley on my Jackson DKMG, but not sure how good they'd be for a bass.

Bass strings for metal... dropped tuning?
I have to recommend the D'Addario. Just get the lowest gauge possible if you're going to have it tuned so low, even though it may be rough on your fingers at first.


In C++:How do you make a STRING uppercase?

I am working with a string being passed in from a client. I am comparing this string to a preset value.





In order to do this, I need to make the incomming string capital. I know toupper will only work on char.





How can I make a string all uppercase?

In C++:How do you make a STRING uppercase?
Not as such, but you can write one without much trouble.





void stoupper(std::string%26amp; s)


{


std::string::iterator i = s.begin();


std::string::iterator end = s.end();





while (i != end) {


*i = std::toupper((unsigned char)*i);


++i;


}


}
Reply:One other oddball suggestion. If you can store the preset value in a string, you can use the built in function compare. More information at the URL below. Pivy.


Read specific pattern string from a file in C?

My file is something like 1 10 20 308


How can I read each value individually and store in a int or string array?

Read specific pattern string from a file in C?
all info stored in a file is stored in "char" (8 bit) format, so you would have to know which numbers were originally integers or strings (or whatever). and read them out the way they were written in.





your example 1 10 20 308:


would be stored in the file like (in HEX to make it easier):


0x01 0x0A 0x14 0x01 0x34


there isn't any way to tell what this represents unless you know how they were stored.


it could be all char which would mean 1 10 20 1 52
Reply:I believe you'd use something like this:


fscanf(filePointer, "%d", %26amp;intArray)


in a loop until fscanf returns "null" for end-of-file.

imperial

In Visual C++, how do you reverse a string?

the code that i have so far is:





#include "stdafx.h"


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;string%26gt;


using namespace std;


string Reverse(string);





int _tmain(int argc, _TCHAR* argv[])


{


string data = "Hello There";





cout %26lt;%26lt; "The reverse of " %26lt;%26lt; data %26lt;%26lt; " is " %26lt;%26lt; Reverse(data) %26lt;%26lt; endl;





system("PAUSE");


return 0;


}


string Reverse(string x) {





int counter;


string NewString(x);





//enter something here





return NewString;


}

In Visual C++, how do you reverse a string?
reverse( NewString.begin(), NewString.end() );





(You will have to #include %26lt;algorithm%26gt; )
Reply:const string %26amp; reverse( string %26amp; s )


{


return (s = strrev( s.c_str()));


}
Reply:easy... from the top of my head (might need some changes in slight syntax, but heres the idea)





char temp;





for (int x = 0 ; x %26lt; NewString.length() ; x++)


{


//swap two characters


temp = NewString[x];


NewString[x] = NewString[NewString.length()-x ];


NewString[ NewString.length()-x ] = temp;


}





The only things im not sure about are .length(), whether [x] on a string is the right syntax to get a single character, and whether temp should be a string or a char. good luck


How do i concert in c++?

how do i convert a string to a character ins c++? need it so i can compare ascii values.

How do i concert in c++?
if you declare a char array and use name.get(), you'll pull out one character at a time.
Reply:See this:





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


Guitar Strings Sound Metallic... May Be Strings Hitting on Frets... Is It Just Cause I Need to Break Them In?

I have G'Aggradio (or Something like that... I'm too lazy to get up and look now.) .10 Gauge Strings. I play Metal, and tune it to three different tunings:


C G C F A D


D G C F A D


D A D G B E


which may be bad for my strings, which is unrelated to the question but just throw that in your answer please.





I just put my strings on at about 8 00 tonight, and played it like 5 seconds after I put them on. When I hit some of the lower strings (which is constant in metal songs), it makes a noise that can be described as a "buzzing, metallic sound." I told a guy to modify my guitar to play with .11 gauge strings, but would that make much of a difference?

Guitar Strings Sound Metallic... May Be Strings Hitting on Frets... Is It Just Cause I Need to Break Them In?
It sounds like you aren't putting enough pressure on the strings. I have D'Addario strings on both my Alvarez Classic guitar (EXP 45) and my Martin D-28 acoustic (EJ-16)... I really like the sound they give but they are very critical as to the amount of pressure you apply to them... sloppy playing techniques will show up immediately... usually by giving off a fret buzz.


Java strings...?

i need to compare to strings (or even chars if it's easier for you)


meaning i have


static int[] x = new int[30];


static string[] a = new string[100];





and somewhere i have to do this:


if (a[x[k-1]]==a[x[k]] %26amp;%26amp; a[x[k]]!="e" || a[x[k]]!="i") - which is fine in C++ but not in java. how do i compare 2 strings





PS i just need to know how to convert == and !=. and i don't want any references to the string class

Java strings...?
In java you do not use == or != when comparing strings. Instead use:





if (myString.equals("e")) -- to replace ==


if !(myString.equals("i")) -- to replace !=
Reply:If you prefer to use equal() method to compare the two strings. You can download the example code here :

elephant ear

When I used string data type in my c++ programme, it shows error i.e. data type expected.?

as per i know, string is also a data type, but when i declare variable with string datatype, error is data type expected, variable not declared , ect.


so, for alternative, i used char datatype, but it accepts character till space %26amp; ignore(or assign to next variable) character entered after space, plzzzzzzzzzz help me

When I used string data type in my c++ programme, it shows error i.e. data type expected.?
Are u sure ur working in c++ not vc++? In c++ string is NOT data type i am damn sure. If ur reading the chars with cin function it reads only till blank space and thinks end of string so u wont get anything after space. Instead u use getche() function. This program is nothing to do with string.h. include string.h for strcmp,strlen etc function if required.
Reply:There Is U Haven't Included #include%26lt;string.h%26gt; Else There Is No Error,Means U May Haven't Included..
Reply:If you are using the STL string class then you probably want to add at the top:





#include %26lt;string%26gt;





and:





using namespace std;
Reply:Hmm...do you have to #include string.h?





The char datatype only takes one character. If you're looking to store words or phrases, you should use a string. What does the error message say exactly, and what syntax are you trying to use to declare the string?


How do I convert a string to an int in C++? Preferably the hard way..?

Okay, lets say that i have a string id;


Whatever is in the variable id is user entered. So I can't just say int num = atoi("pat");





and id MUST be a string.





if i wanted to do:


num = atoi(id);





How do I do this conversion without getting this error when compiling:


error: cannot convert `std::string' to `const char*' for


argument `1' to `int atoi(const char*)'





any other way is fine that isn't too complicated. I just want the value of the string to be an int.

How do I convert a string to an int in C++? Preferably the hard way..?
Try int i = atoi(id.c_str());
Reply:The best and least error prone way is to go through each character one by one and look at the ascii code.





If you try to convert the letter 'a' for example to an integer you will have problems, so look at it's ascii value in order to not cause a runtime error.





If the ascii value does not equal the ascii values for the numbers 0-9 then it is not a valid integer and an exception should be thrown.





chars = myString.c_str();





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


{


if(chars[i] %26gt; 48 %26amp;%26amp; chars[i] %26lt; 58)


{


convert to int here;


}


}





then you will want to multiply each of the result ints by the appropriate multiple of 10.





if these are your ints





3


4


2


5


= 3,425 (int)





you need to do this





completeInt = (3*1000) + (4*100) + (2*10) + 5;





this will give you the int you desire.





This whole approach might seem unnecessary but,if you don't check to see if they are not letter or symbols first, you will have problems in the future.
Reply:What the first answerer said would work. Or take a look at http://forums.devshed.com/showpost.php?p... , especially at the part where stringstreams are used. Use a stringstream to take in a string, and force it to output to an int. If it succeeds, the conversion was successful.





What I don’t recommend you do is attempt what El Gordo has done. The best and least error prone way is to use pre-written code, especially one that has been written and tested by extremely smart people, like say, the ones who made your compiler. There is a way to do it with standard C++ or C functions, so rely on them.
Reply:You can get rid of your compile error by using the c_str() function to convert the std::string to a const char*. num = atoi(myString.c_str()).





I think you need to do more checking of the user input string, though. Read up on what atoi does when it's handed a string that contains characters that are not numbers. You probably need to analyze the string before just passing it to atoi(), try writing your own function IsNum(char ) and pass each letter to this function. If one of them is not a number, display an error message to the user. If all letters pass, then call atoi( ).


Split a string into 3 variables in C?

I have a string separated by commas, that I want placed into variables.





ex.


char string[50] = "here, it, is"





// SOME CODE EXECUTES





str1 = "here";


str2 = "it";


str3 = "is";








What code should I use?

Split a string into 3 variables in C?
You want to extract tokens from the string, given a delimiter. There is a function in C for this, called strtok.





http://cppreference.com/stdstring/strtok...
Reply:char str[50] = "here,it,is";





char *pch;


pch = strtok(str,","); //get token 1 - (here)





while(pch != NULL)


{


cout%26lt;%26lt;pch%26lt;%26lt;endl;


pch = strtok(NULL,","); //first get - (it) and then (is)


}





Hope this helps!


Saturday, May 22, 2010

String.h header file in C++ programming?

what are the functionas that i can use using the header file string.h

String.h header file in C++ programming?
Take a look at





http://www.cs.cf.ac.uk/Dave/C/node19.htm...





You can also look at your string.h file directly to see what functions are listed.
Reply:it as all the manupulation function





strlen() string length


strcat() " concat





strcmp comparision





strrev() reverse





and so on

lady palm

Plz make this c++ program for me...ive tried but cant...?

make a C++ Program which will take the string as input during run time and will display the different arrangements of string on Console.User can enter spaces and enters while entering string during run time.String can have alphabets, numbers and special characters and spaces and enter characters.Your program will do the following


1. Will display the user entered string in the same order as the user entered, without spaces and enter characters


2. Will display the string in a reverse order printing from end to start without spaces and enter characters


3. Will display the string with spaces and enter characters in it, in the order as user entered.


4. Program will display the string with spaces and enter characters in it in the reverse order as users entered.


5. User can enter any number of characters even more than 2000 characters.

Plz make this c++ program for me...ive tried but cant...?
Honey, the program isn't that complicated, but it will take awhile and frankly I don't feel like doing your homework for you. (Although it's an interesting problem...)





Some suggestions, most of which you should already know:





1) Plan the thing out BEFORE you get near a keyboard. A major mistake newbie programmers often make is to just start typing. That way lies the kludge.





2) How are you going to have the user input the string? Since the problem specifically says that the enter keys should be recorded as well as spaces and the like, and most of the built-in streams delimit on enter, you're going to have to find another way to do it. How about a loop, reading one key at a time? You'll have to find a way for the user to let the program know that you're done entering data - perhaps pressing the Escape key will do it. Testing for that should be easy. I would suggest a post-test while. However, using a loop like this will make other problems of yours - specifically, storing the characters in an array without spaces and keeping track of spaces and enters - much easier.





3) How are you going to structure the array for spaces and enters? You'll have to have some way for the program to know where to re-insert them in the original string, as well as a way to differentiate between them. My first thought would be a two-dimensional array, with the first element of each row being the location of the "object" and the second being a code to indicate which "object" it is.





4) Once you have those, item 3 will solve itself. Just a loop starting at the beginning and interpreting the data in the two arrays.





5) Item 4 isn't much harder - the same loop as the other but starting at the end of the array and decrementing as you go.





6) That bit about "any number of characters" indicates that you're either going to need to reserve a huge array to hold them or you're going to need a dynamic array. If those last two words ("dynamic array") don't make any sense to you, you probably aren't expected to be able to do that.





7) Once you have your algorithm planned out COMPLETELY, do a desk check on it before you start coding. A lot of newbies skip this step, too, and it costs them. You want to know your program is going to work before you spend time and effort in coding it. Once again, the word "kludge" rears its ugly head.





I know this is tough, but trust me - the skills you're learning here will help you more than you can imagine later on when you're writing the programs you want to write.