Tuesday, July 14, 2009

Combination of String in C++?

i wish to get different combination from a String. For example: String^ str = "a,b,c,d,e";


i will wan to separate the string into individual letters and form all different combination like (a,b), (a,c,d) or (a,b,c,d) etc..


is there any simple methods to do so juz using loop?? im still a beginner in C++ so i dun really noe any built in methods. But if haf i will wish to learn too. pls help!! thx

Combination of String in C++?
I know of no easy way of doing the task you want to accomplish using a built in library function of C/C++. Basically, there are a few things you will need to do:





1. Parse out each of the comma separated characters and create a set containing each of those characters (this set could be stored in an array of chars).





2. Print the power set of the character set you have. The power set is the formal name for what you are looking to print. A simple algorithm for this would be to start with the first element in your list and combine that with each of the characters after it. Once all combinations involving the first character have been exhausted, move on to the second but only do combinations of the second not involving the first character which came before it. Do this for each character in the set and your task will be accomplished.





This problem is ripe for recursion if you are so inclined.


String manipulation C++?

Hi i am working on a small program where a user enters a string which should be more than 8 characters. Then once they have entered a string, the program should do the following:


1) output the size of the sentence


2) output the 1st 3rd 5th and 7th letter and append it to the end of the inputted sentence.





This is what i have done so far but i am getting errors and i am new to c++:





#include %26lt;iostream%26gt;


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


#include %26lt;sstream%26gt;


using namespace std;





int main()


{


int iQuit;


char str[7];


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


getline(cin,str);


cout%26lt;%26lt; "Size of the sentence" %26lt;%26lt; str.length() %26lt;%26lt; endl;


cin %26gt;%26gt; iQuit;


return 0;


}





Can someone help on this and the second part please? i could probably do this in java but i need to do in C++.





I would appreciate it if someone can help me on tell me they have done in such a way?

String manipulation C++?
There are two main kinds of string in C++, the null terminated strings inherited from C and the C++ string object. Using the latter makes your assignment a cinch. Unless you are instructed otherwise you should begin to use string objects and move away from null terminated strings whenever possible.








#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





int main()


{


string input;





while (input.length() %26lt;= 8)


{


cout%26lt;%26lt; "Enter sentence at least 8 characters in length\n";





getline(cin, input);


}





cout%26lt;%26lt; "Size of the sentence = " %26lt;%26lt; input.length() %26lt;%26lt; endl;





input += input[2];


input += input[4];


input += input[6];





cout %26lt;%26lt; "appended sentence is: " %26lt;%26lt; input %26lt;%26lt; endl;





return(0);


}
Reply:Try this code for starters. Can you spot the changes?





#include %26lt;iostream%26gt;


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


#include %26lt;sstream%26gt;


using namespace std;





int main()


{


int iQuit;


string input;


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


getline(cin, input);


cout%26lt;%26lt; "Size of the sentence " %26lt;%26lt; input.length() %26lt;%26lt; endl;


cin %26gt;%26gt; iQuit;


return 0;


}
Reply:You can't say str.length(). You have to use the function strlen(), like this:





cout%26lt;%26lt; "Size of the sentence" %26lt;%26lt; strlen(str) %26lt;%26lt; endl;





To output the 1st, 3rd, 5th and 7th letters you have to access them from the string/character-array. This is done like so: str[0] is the 1st. str[2] is the 3rd letter, etc.





Appending is easy. Just make a new character array that is bigger, copy the inputted string to it (using the strcpy function) and then assign the letters that you want to the new string.

forsythia

C++ programing, this is my study guide can you help me get the right answers?

1. Making a variable behave like a variable of a different data type is known as


a.typecasting


b.brute force


c.intimidation


d.variable casting


2. To redirect the input for a C++ program (theprog.exe) to come from a file rather than the keyboard you would:


a.theprog %26lt; infile.txt


b.theprog %26lt;%26lt; infile.txt


c.theprog %26gt; infile.txt


d.theprog %26gt;%26gt; infile.txt


3. if a do/while structure is used,


a) an infinite loop will not take place


b) counter controlled repetition is not possible


c) the body of the loop will execute at least once


d) an off-by-one error will not occur


4. A function prototype does not have to


a)include parameter names


b)terminate with a semicolon


c)agree with the function definition


d)match with all calls to the function


5. A function prototype does not have to


a)include parameter names


b)terminate with a semicolon


c)agree with the function definition


d)match with all calls to the function


6. For command line arguments you write your main function:


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


The argc refers to:


a.the count of the arguments passed


b.an array of pointers to strings


c.the number of people using the program


d.the size in bytes of the program

C++ programing, this is my study guide can you help me get the right answers?
1. a.


2. d.


3. c.


4. d.


5. isn't this #4?


6. a.
Reply:1. a


2. a -- I think


3. c


4.a - i think


5. same as 4 ?


6. a





Number 4 - example of prototype


void function(int number) will work if you do this as well


void function(int) I don't think poster above said it right








I know this will work.





Man whoever gave you the study guide -- really likes a answers :)





number 2 - site below answers the question. And thats what I thought before I went and looked, so I am right


C++ prog. Problems with a String class. (the same as in my previous question): what's wrong with it? copy fct?

.h::::::::::::::::::::::::::::::::::::::...


#ifndef STRING_H


#define STRING_H


#include %26lt;iostream%26gt;


namespace HomeMadeString


{


class String


{


unsigned int elementsNum;


char*pData;


public:


String()


{


elementsNum=0;


char*pData=NULL;


}


String(String %26amp;theOther);


String(const char* c1);


String(char c, unsigned int times);


~String()


{


delete[] pData;


}


void getStr(char * pBuff);


unsigned int getLength(){return elementsNum;}


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


char getChar(unsigned int pos);


static String concatenate(String string1, String string2);


static bool compare(String string1, String string2);


static void copy(String%26amp; string1, String string2);//it copies the second string into the first


};


}


#endif


.cpp::::::::::::::::::::::::::::::::


How to write the "copy" function?


The "print" function?





Please help!





Domonkos

C++ prog. Problems with a String class. (the same as in my previous question): what's wrong with it? copy fct?
You get that char*pData inside your constructor is a separate declaration, it does not reference the class-scope variable with the same name (and it falls out of scope when the constructor returns.





Also, your code is conspicuously lacking any allocations -- don't rely on memory allocated by the caller, it could go away at any time.





More, avoid implementation inside of the .h file, it will bite you in the butt when your projects become complex.





Copying an object is usually done as a self-referential overload of the constructor, accepts parameter of its own class.





Not sure what you want print() to do, print to a printer? Doesn't seem to make much sense. If you mean print to console, what's wrong with printf() or stream output?





Good Luck


C++ study guide help?

1.Which of the following can contain data items of different types?


a.an array


b.a structure


c.a string


d.none of the above; they can only contain different values


2.For a main function defined as following:


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


Which statement below is NOT correct?


a.The first argument tells how many separate arguments were passed.


b.The second argument represents an array of strings.


c.The first (i.e. the 0th) argument is the name of the program


d.The first (i.e. the 1st) argument is the name of the program


e.none of the above


3.In C++, all variables


a.take up the same amount of storage on a certain computer type


b.take up the same amount of storage on all computer types


c.take up different amounts of storage depending on the data type


d.take up different amounts of storage depending on the length of the variable name


4.Every element of any array takes up one byte in memory


a.true


b.false


5.In object oriented programming the constructor


a.is the method called when you create an instance of that class


b.has the same name as the name of the class


c.is used to initialize variables


d.all of the above

C++ study guide help?
1-a , 2-e(maybe) 3-c 4-b 5-d


ASP 2.0 C# Access Connection String?

Can someone post a sample connection string to connect to an Access mdb file (not using SQL) in C#? I am using ASP.NET 2.0, but can only find SQL connection strings. Thanks.

ASP 2.0 C# Access Connection String?
http://www.carlprothman.net/Default.aspx...





You will always use a SQL statement to gather your info from the db.
Reply:Here is a sample.





Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data\rebuilt.MDB





You can click on the top menu "tools" selection and select


"Connect to Database..." Select "Microsoft Access Database File", click Continue, browse to the database to open, and the connection will be added to your project.

jasmine

Is there any situation in which it would be useful to create a matrix of bools or string in C++?

Lets say we have a Matrix program in C++, and we are using template, I want to know if you have an example of a situation in which it would be useful to create a matrix of bools. How about a matrix of strings?

Is there any situation in which it would be useful to create a matrix of bools or string in C++?
mmm.. yeah... think about it. name yes/no
Reply:a matrix of bools could represent a very simple bitmap (in black/white), or possibly a map of some kind that indicates specific points of interest.





if it's a sparse-matrix, then you can get away with simulating it using a chained hashtable, which will save memory %26amp; time.


Physics Help -Three Pulling Strings - Please Quick?

Three strings, in the horizontal plane, meet in a knot and are pulled with three forces such that the knot is held stationary. The tension in string 1 is T1 = 2.1 N. The angle between strings 1 and 2 is q12 = 130� and the angle between strings 1 and 3 is q13 = 120� with string 3 below string 1 as shown.


a) Find the tension in string 2.





T2 = N


b) Find the tension in string 3.





T3 = N


A mass of 1.1 kg is now placed on the knot and supported by a frictionless table in the plane of the strings. c) Find the acceleration of the mass if all the forces remain the same as above.





|a| = m/s2


d) If the sizes and directions of T2 and T3 remain the same, but T1 is increased by 2.4 N, what is the acceleration of the mass?





|a'| = m/s2

Physics Help -Three Pulling Strings - Please Quick?
The knot is held stationary =%26gt; T1 + T2 + T3 = 0(in vector)


=%26gt; Consider reference frame Oxy with: Ox - direction of string 1, Oy - perpendicular with string 1.


=%26gt; Ox: T1 - T2*cos50 - T3*cos60 = 0


Oy: T2* sin50 - T3 *sin60 = 0


=%26gt; T2 = T1/[(cot50 + cot60)*sin50] = 2.3N


T3 = T1/[(cot50 + cot60)*sin60] = 2.0N


All the forces remain the same =%26gt; net force is 0 =%26gt; a = 0


T2 and T3 remain the same, T1 increase be 2.4N =%26gt; net force F = 2.4N =%26gt; a = F/m = 2.2 m/s2


Can you tune a violin to include a C string?

You mean to add another string or, for example, just tune a A to C? If it's the latter, yes it's doable... but why would you want to?

Can you tune a violin to include a C string?
Custom 5-string Violin? Yes.


Ladies: would you or have you tried the C String?

heres the link


https://www.cstringdirect.com/

Ladies: would you or have you tried the C String?
lmao..


i think every lady needs one in her closet !
Reply:you are going to find it under your christmas tree


:) Report It

Reply:Maybe


I would be interested only if I was given one


Can you say Yeast Infection....





Ssshhhh holla ;P
Reply:Havent tried and I dont wear panties so its not a problem for me. lmao
Reply:it looks like a pad....im sory, it does.








heck no
Reply:I don't get it. How does it stay in place? And how did you come across this interesting invention?
Reply:Why bother? Might as well go commando!
Reply:that looks interesting


MO
Reply:Wow...and what is the point of wearing anything at all??? To catch the discharge??? GROSS. It's doesn't even look comfy. It looks like it would be shifting all day long.
Reply:no
Reply:Hmmm, nope, never even heard of that one! We are so sheltered here in the midwest! lol Not sure about all that, kinda looks like a headband for your ummm.... lol
Reply:It looks like a headband...I wonder if thats how they came up with it. Just stuck a headband there. lmao!!





No.


Have not.


%26amp; probably wont.
Reply:how much would you pay me to try it on.
Reply:No, I might as well not wear any underwear
Reply:No! They look uncomfortable and tight, probably plastic under there or something to keep shape. They don't look that sexy either. It looks like a pad.
Reply:No and No.





It looks like it would fall off.





Is there even anything on the back?





I am going to pass on that one.








(( %26lt;3 Bella %26lt;3 ))
Reply:You know I will try anything once. Let me know when to schedule my fitting.
Reply:Thank you, i just found what the other half is getting for Christmas lol
Reply:No way!! I'll stay w/ the G string. Seems like the C string may slip and slide a little bit.
Reply:no, i haven't. i wouldn't either. i don't know. that's a little too far out there.
Reply:wow %26gt;:) *evil grin*
Reply:How does it stay up? It doesn't look like there are any strings? What if you had to run to catch the bus? It looks like the new style of earmuffs they have out ...? I going to pass on those......?
Reply:I never have, but I might- I usually don't wear any panties.
Reply:Wow. My contacts sometimes show me the most interesting things.





I'm sorry. Carry on.
Reply:OMG no thank you.





well maybe... it depends... like if i was going out and i was wearing a dress but not for everyday use. so i would probably try it.
Reply:no, i'll stick with my long underwear..
Reply:I have this mental image:





Running to catch bus. Everyone staring at me as someone yells: "Oh Ma'am, you dropped your uh....uh......uh yuh..something, " as twenty people point %26amp; laugh.
Reply:no, thats like wearing a pad with no underwear lmao
Reply:No but maybe for you babe! LOL! =) ♥
Reply:Wow that thing is pointless why would I wear a pad seriously that is not sexy it all i would definitely not wear that i will stay with my G strings, thanks but that is a big no no there...
Reply:just...wow...

crab apple

Would you go commando or wear a c-string?

Definitely commando: never wear the stuff, don't own any. Men are better off without underwear

Would you go commando or wear a c-string?
I usually go commando, depending on where I am going. If its the store, mall, outlet.. mail box, I go commando. If its a doc appt, hospital visit, I wear my undies.


B.C. Rich Warlock string help...?

Alright, so as you saw I have a B.C. Rich Bronze Series Warlock guitar (red). I got it a little while ago, and just today one of my strings broke. It was the e (thinnest) string. I need help with getting it replaced. I'm a beginner and this is my first electric guitar. I read online that some some strings break real easily on it, so I need a kind of string that won't =]. Can I do it by myself or should I give it to the store? If I do it myself (which I'll probably get the previous owner of the guitar to do it for me) what kind of strings should I buy? Name, place available, and price please. Thanks a lot guys!!!





P.S. I know this is silly but I have no idea what I'm doing, except for playing, with a guitar. =D

B.C. Rich Warlock string help...?
High Es (9s or 10s) can break a lot, because they are a thin gauge and you might strike them hard... Go to a shop and buy a bunch. They should only be about 25 cents each.


Whats better to look for...a g-string or a c-string?

A C-string. Though they're ususally pretty thick - it's kind of hard to break one. Rosin-coated?

Whats better to look for...a g-string or a c-string?
LOL....funny..of course a G string.
Reply:how about a v-string? ;)
Reply:I prefer a pearl v string form fredericks of hollywood
Reply:If I were a lady, my wardrobe would have the complete array of g-strings, v-strings and c-strings. C-strings are a very important and exciting fashion innovation and I'm glad my girlfriend has a nice set of them.


What's the standard functions for string process in C++?

I'm learning C++ programming. In my textbook, I only find some function for string processing such as "strcmp" or "strcat". But they are more widely used in old C. I want to know some newer function for string in C++, which process strings as "objects"?


If you know, tell me in detail (examples are best), Plz! Thanx.

What's the standard functions for string process in C++?
See: http://cplusplus.com/reference/string/st...





The page above describes what a string object is in C++ and gives details on its member functions and avaliable operations.








For example, assume:





std::string a = "Test"


std::string b = "Example"





Then, strcmp and strcat in C++ with string objects would be:





if ( a == b ) a+= b;





That is, if a is the same as B ( value wise ) then make a's value the sum of the value of a and b ("TestExample")

strawberry

C++ string question?

a program that takes an input string from the user and outputs as a single string, the first word following the first comma, the second word following the second exclamation point and the third word following the first semi-colon.





For example if the input string is:





?; Moon? Area! Formula, Precision; Label! First? Last! Text





The result would be





Precision Last Formula can u pls pls give me some ideas or codes to do it?ty

C++ string question?
Search for the first comma and then get back until you will find a space, and write on the screen the characters. Do the same for others.


C++ string?

write a program that reads into a string object a name with three blanks between the first and last names. Then extract the first and last names and store them in separate string objects. write a function subproram that displays its string argument two times. call this function to display the first name four times and then to display the last name six times

C++ string?
Check out this site:





http://www.mochima.com/tutorials/strings...





It's got a tutorial that will show you how to do everything you need to do for your assignment!


C++ string help?

I need the user to input:


-the name of the file to read from


-name a file to be created to output the data





Ignoring the rest of the program, here is the part i'm having problems with:





#include %26lt;string%26gt;





int main()


{


// Filenames


string inFilename = "";


string outFilename = "";


// For file I/O


ifstream fin; //input file stream


ofstream fout; //output file stream





//User input of file name


cout%26lt;%26lt;"Enter the name of the input file: ";


getline(cin,inFilename);


//Works fine at this point, and opens the named file





//User input of file name


cout%26lt;%26lt;"Enter the new filename: ";


cin%26gt;%26gt;outFilename;


getline(cin,outFilename);





return 0;


}





When I compile I get no errors, but when I run the program, it will open the original file fine, but the output file won't pass the validity check, and won't even output the name of the file I had the user input in the error code as called for. What is the difference between the two!?!??!

C++ string help?
Actually, I don't see how that code is doing what you want. Try this;





std::string infilename;


std::string outfilename:





int main()


{





std::cout%26lt;%26lt;"please enter file to be opened"%26lt;%26lt;std::endl;


std::cin%26gt;%26gt;infilename;





fstream in(infilename.c_str(), ios::in);


if (in.good())


{


std::cout%26lt;%26lt;"file opening successful....."%26lt;%26lt;std::endl;


}





else if(in.bad())


{


std::cout%26lt;%26lt;" file opening failure....."%26lt;%26lt;std::endl;


return 0;


}





std::cout%26lt;%26lt;"please enter output filename"%26lt;%26lt;std::endl;


std::cin%26gt;%26gt;outfilename;





ofstream out(outfilename.c_str(), ios::out);


out%26lt;%26lt;"hi, I'm writing to this file!"%26lt;%26lt;std::endl;





in.close();


out.close();





return 0;





}


C++ string editing?

ok using


#inlcude %26lt;iostream%26gt;


and


#include %26lt;cstring%26gt;





im wanting to make a program that takes a string you enter and replaces certain characters int he string with spesific other characters


like an ecryptor, but not for that perpous


now i got so far as to have the user enter the string with cin.getline


but i dont know how to have the program read the string and act on it





p.s. im willing to go throgh a tedious proccess of listing the characters and there replacements so all i need to know is how to read the string, and replace spesific characters with other spesific characters


ok?


ok.


=]

C++ string editing?
Code to iterate thru the string and replace all the


character a with character b





string::iterator It = str.begin();





while ( It != str.end() )


{


if ( *It == ' a' )


*It = 'b';





}


cout%26lt;%26lt;str





Hope this help
Reply:Using character strings (declared like you have, such as char str[N]; or char* str;) makes dipping into the string to deal with individual characters easy, because your string is really an array. So the first letter is at str[0], the second is str[1], and so on. So let's say I wanted to search through my string and replace the letter a with the letter B (and capitalization does matter!). I would write:





int i = 0, n = 5000;


char str[5000];


.


.


Read in string


.


.


while (i %26lt; n) {


if ( str[i] == 'a' ) str[i] = 'B'; //Note that I used single quotes


i++; //i = i+1;


}





So if my string was "Apple's are very great!" to start with, it would end up being "Apple's Bre very greBt!".

kudzu

C++ string functions help?

I need to write a library similar to the %26lt;string.h%26gt; header file. I need help writing the following functions. They are included in my own class called "string".





void resize(unsigned int, char);


//resizes character array "Buffer" to number specified by


//first parameter


//fills extra space by the second parameter character





void insert(unsigned int, string %26amp;);


//Inserts a string into "Buffer" a character array.


//First parameter: Place to insert


//Second parameter: string to insert.








void remove(unsigned int, unsigned int);


//removes characters from "Buffer", a character array.


//First parameter : Starting position,


//Second parameter : number of characters to remove.

C++ string functions help?
Okay, this is pretty obviously homework. I won't show any code here, but I'll give you an idea how to implement the functions listed.





First, void resize(unsigned int, char); It has to do these things in approximately this order:


Validate int as greater than zero, or the operation is over before it starts. Next, it needs to allocate memory for a new Buffer with the extra space. Oh-oh. How do you find the buffer if it doesn't return a pointer or a reference to it? Better change the return type to char%26amp; or char *. Okay, now the new characters are written into the new buffer and then the old characters ... Oh-oh, we need to know where that things at too. Better include a reference or pointer to the old buffer as a parameter. So we take the old buffer and move the old characters over into the new buffer behind(?!) the new characters. Rats! Do we need to consider that the new characters should always be prepended or appended or does it change?





void insert(unsigned int, string %26amp; old_string, string %26amp; new_string); maybe?





void remove(unsigned int, unsigned int, string %26amp; buffer);





Unless you MUST follow these exact prototypes for your assignment, you may want to consider these modifications.





I think you can work these last two from the first walk through I gave you. They aren't really any different as to the mechanics of the problem, just what information is needed to operate from. Good luck!
Reply:I can understand that. Next time post partial code with specific questions and I (we?) can take the sting out of those sticky points. Sorry to be a drag. Cheers! Report It

Reply:Sounds like homework to me...


And if you can't do these simple things, you are in trouble!


Do it as a for(i=..;i%26lt;..;i++) loop, and use Buffer[i].


(or review the use of pointers: that's the beauty of C)


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.


A simple question on C, "Convert string to integer"???? pls help urgent.?

So i have this project.. where i have to specify a=1,b=2, c=3... etc.. and when i enter a string as an input say "cab" the program should print "312" as the answer... pls give a "C program" Thank you..

A simple question on C, "Convert string to integer"???? pls help urgent.?
Change string to integer











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


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





int main(void)


{


char num[80];





gets(num);


printf("%d", abs( atoi( num ) ) );


return 0;


}





======================================...


There are several methods, the easiest being 'atoi()' the most flexible IMHO (in terms of error checking) being 'strtol()':








/* ATOF.C: This program shows how numbers stored


* as strings can be converted to numeric values


* using the atof, atoi, and atol functions.


*/





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


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





void main( void )


{


char *s; double x; int i; long l;





s = " -2309.12E-15"; /* Test of atof */


x = atof( s );


printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );





s = "7.8912654773d210"; /* Test of atof */


x = atof( s );


printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );





s = " -9885 pigs"; /* Test of atoi */


i = atoi( s );


printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );





s = "98854 dollars"; /* Test of atol */


l = atol( s );


printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );


}





Output





atof test: ASCII string: -2309.12E-15 float: -2.309120e-012


atof test: ASCII string: 7.8912654773d210 float: 7.891265e+210


atoi test: ASCII string: -9885 pigs integer: -9885


atol test: ASCII string: 98854 dollars long: 98854





/* STRTOD.C: This program uses strtod to convert a


* string to a double-precision value; strtol to


* convert a string to long integer values; and strtoul


* to convert a string to unsigned long-integer values.


*/





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


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





void main( void )


{


char *string, *stopstring;


double x;


long l;


int base;


unsigned long ul;


string = "3.1415926This stopped it";


x = strtod( string, %26amp;stopstring );


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


printf(" strtod = %f\n", x );


printf(" Stopped scan at: %s\n\n", stopstring );


string = "-10110134932This stopped it";


l = strtol( string, %26amp;stopstring, 10 );


printf( "string = %s", string );


printf(" strtol = %ld", l );


printf(" Stopped scan at: %s", stopstring );


string = "10110134932";


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


/* Convert string using base 2, 4, and 8: */


for( base = 2; base %26lt;= 8; base *= 2 )


{


/* Convert the string: */


ul = strtoul( string, %26amp;stopstring, base );


printf( " strtol = %ld (base %d)\n", ul, base );


printf( " Stopped scan at: %s\n", stopstring );


}


}








Output





string = 3.1415926This stopped it


strtod = 3.141593


Stopped scan at: This stopped it





string = -10110134932This stopped it strtol = -2147483647 Stopped scan at: This stopped itstring = 10110134932


strtol = 45 (base 2)


Stopped scan at: 34932


strtol = 4423 (base 4)


Stopped scan at: 4932


strtol = 2134108 (base 8)


Stopped scan at: 932


======================================...
Reply:giving program is tough but you can use switch case for that.
Reply:you have to put the letters "cab" into a different type of put statement. Try this:


var a:=1


var b:=2


var c:=3





put ""c" "a" "b""





I belive this is how you do it. I haven't worked with C in awhile so you may have to do some slight tweaking. (where I put the letters"var" you may have to change to "int"
Reply:If the numbers of the letters remained fixed and ascending (so a is some number, b is always 1 higher than a, c is always 2 higher than a etc...) Then you can take advantage of the fact that c stores strings as an array of chars and characters are stored as numbers. Also all your characters must either be lower case or upper case.





Here's an example





void print_string(char *string)


{


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


{


printf("%d", (int)(string[i] - 'a' + 1); //So a is 1, b is 2, c is 3 etc...


}


printf("\n");


}
Reply:use atoi()





you will have to convert the chars to the correct number before trying to get the value of it.





do you need it to be an int? can't you just use strings that are numbers? ie "1", or "2".
Reply:In C characters and integers are like twins. I would explain like this.





1)Each character is stored in memory as its ASCII Value. For example the ascii value of 'A' is 65 so 65 is stored there.





2) So first I get the string. Since string is an array of characters, I traversing through it.





3)I convert them to upper case because 'a' has a different ascii value than 'A'.





4)Then I subtract the ASCII value of each character from 64 (because A starts from 65).





5)There you have the answer!!





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


void main()


{


char name[25];


int i;


clrscr();


printf("Enter the string:");


scanf("%s",name);


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


printf("%d",toupper(name[i])-64);


getch();


}
Reply:You can check here. http://zombay.com/forum/convert_string_t...





I think this is the most best answer.





If you have any other problem in programming, you can post in http://zombay.com/forum/programming-b45....





You may get good help. It's free to register.


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.

garland flower

(C++)The output for the sample string would be what?

Given a "C" style string such as char[] s1 = "ka2d23UkLeA2" write a main function program that will count the number of occurrences of the character 'a' and 'A' and the number of occurrences of the character '2'.


The output for the sample string would be:





The number of As is 2.


The number of 2s is 3.


//please help

(C++)The output for the sample string would be what?
Yeah, all you need to do is loop through all of the characters in the array.





char myArr[] = "hello 2nd chascity.";





Create the loop





For(;;)


For(int i = 0; i %26lt;= int(strlen(myArr)); i++)


While (myArr(i) != "/0")





test all the values





If (myArr(i) == "a"){...}


switch (myArr(i)){


Case 'a': ...}





record values


int aFound = 0;


aFound ++;





int i = 0;


int aFound = 0;


for(;;){


if (myArr(i) == "a"){


aFound++;}


}


cout %26lt;%26lt; aFound;








That just test 'a' but you can do the same for the rest
Reply:int num_a = 0;


int num_2 = 0;


int i = -1;


char[] s1 = "ka2d23UkLeA2";





while (s1[i++] != '\0') {


if (s1[i] == 'a' || s1[i] == 'A') num_a++;


if (s1[i] == '2') num_2++;


}





printf("In the string \"%s\" there are %d A or a's, and %d 2's", s1, num_a, num_2);
Reply:google digiu


C program to Insert a string into a given string,To find the specified charcter in the string?

C progarm to find the Specified character in the String


and C program to insert a string into a given string.





C program to find Fibonacci Numbers

C program to Insert a string into a given string,To find the specified charcter in the string?
1) C progarm to find the Specified character in the String


%26gt;%26gt; copy the next code to your compiler








//////////////////////////////////////... Beginig of the code


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


char toup (char c)


{


if(c%26gt;= 'a' %26amp;%26amp; c%26lt;='z')


return c - 'a' + 'A';


return c;


}


int main ()


{


char s[81], c[3];


int i,f[81],flag=0;





printf("Enter The string: ");


scanf("%80s",s);


printf("Enter the char you want to find: ");


scanf("%1s",c);


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


if(toup(s[i]) == toup(c[0]))


f[i] = 1 ,flag=1;


else


f[i] = 0;


if(flag)


{


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


printf("\n\nThe char \"%c\" was found in :\n",c[0]);


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


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


if(f[i] == 1)


printf("Position %i\n",i);


}


else


printf("The char \"%c\" is not found in the string.\n",c[0]);


scanf("\n\nEnter any number to Exit%i",%26amp;i);


return 0;


}


//////////////////////////////////////... End of the code


______________________________________...





2) C program to insert a string into a given string.


%26gt;%26gt; copy the next code to your compiler





//////////////////////////////////////... Beginig of the code


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





int main ()


{


char s1[101],s2[101],s[209];


int i,j,c,ind;


printf("Enter the Original String: ");


scanf("%100s",s1);


printf("Enter the subString: ");


scanf("%100s",s2);


printf("Enter the index where you want to insert the subString: ");


scanf("%i",%26amp;ind);


for(i = 0,c=0; s1[i]!='\0' ;i++,c++)


{


if(i == ind)


for(j=0; s2[j]!='\0' ;j++,c++)


s[c] = s2[j];


s[c] = s1[i];


}


s[c]='\0';


printf("\n\nThe String now is:\n");


printf("------------------\n\n%s\n\n",s)...


printf("Enter any key and then Enter to Exit: ");


scanf("%100s",s1);


return 0;


}





//////////////////////////////////////... End of the code


______________________________________...





3) C program to find Fibonacci Numbers


%26gt;%26gt; copy the next code to your compiler





//////////////////////////////////////... Begining of the code


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





int main ()


{


char s1[101];


int n,i,n1,n2,r;


printf("Enter the number of Fibonacci numbers you want: ");


scanf("%i",%26amp;n);


n1 = 1;


n2 = 1;


if(n %26lt; 1)


printf("\a\a\aThe number should be positive\n");


else


if(n == 1)


printf("1");


else


if(n %26gt; 1)


printf("1 1");


for(i=3; i%26lt;=n ; i++)


{


r = n1 + n2;


n1 = n2 ;


n2 = r;


printf(" %i",n2);


}





printf("\n\nEnter any key and then Enter to Exit: ");


scanf("%100s",s1);


return 0;


}





//////////////////////////////////////... end of the code
Reply:This is a C program to find 1st 25 numbers in the series





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


long unsigned int fib(long unsigned int,long unsigned int);


void main()


{


long unsigned int i,j=1,k=1,c;


clrscr();


printf("\n%lu\n%lu",j,k);


for(i=1;i%26lt;=23;i++)


{


c=fib(j,k);


printf("\n%lu",c);


j=k;


k=c;


}


getch();


}


long unsigned int fib(long unsigned int a,long unsigned int b)


{


long unsigned int sum;


sum=a+b;


return sum;


}





The foll is a program to scan a character in the given string


Function to be used - strchr.





Scans a string for the first occurence of a given character








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


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





int main(void)


{


char string[15];


char *ptr, c = 'r';





strcpy(string, "This is a string");


ptr = strchr(string, c);


if (ptr)


printf("The character %c is at position: %d\n", c, ptr-string);


else


printf("The character was not found\n");


return 0;


}
Reply:So you're asking us to give you these programs? That's a bit much...


The first request makes no sense...


The second one: This is very simple. Fibonacci numbers are 1, 1, 2, 3, 5, etc., adding the previous two terms to get the next one. So your code would involve a for() loop, at least three variables, and a printf() statement. You can probably figure it out from there...


If not, email me and I'll try to post one later.
Reply:Still sticking to C.Where are you ?.I'll suggest u to go for java.But any way i'll make a note.





C program to find specified character.I'll write the the logic.





1.Read the string into an array[]


2.Read character to replace


3.Find the length of string


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


search for the specfied character.


if(char==a[i])


{


++count;


print("Occurence found at",i+1)


}





Regarding ur next question it is not clear where to insert (either at specified index or beside last character)





and last one Fibonocci series 0,0,1,1,2,3,5,8,13...





U are asked to find fibonocci number from given number





1.Read number as n


2.if(f==0)


print "This is fibonocci number"





3.set f1=0;f2=1





4. for(i=0;i%26lt;n/2;i++)


{


f3=f2+f1;


if(f3==n)


{


print "This is fibonocci number"


exit(1)


}


f1=f2;f2=f3





}





Try implement in C definetly works.


How do i tune my guitar so that its strings are in F Bb Eb Ab C C ?

I need to know so i can properly tune my guitar so i can learn to play some Placebo songs, my band wanna cover The Bitter End.

How do i tune my guitar so that its strings are in F Bb Eb Ab C C ?
Get a guitar tuner from your local store that sells instruments. Or if you have a key board or a piano you can tune it by hitting the key board note then tune the string to match. The center white key on a piano or key board is C , the next key to the right is D , Next is E and so on. The black keys are flats and majors depending on if you are going left or right on the white keys.
Reply:One thing you could do would be to tune it to a Keyboard, but ideally it would be best to buy yourself a Chromatic Guitar tuner...they sell for about $60 - $100.


Alternatively you can tune the guitar to itself...


Tune it to normal Concert pitch then put your finger on the the third fret on the "D" String and tune your Bottom "E" String to that sound... that will get it to "F"


Then you have a starting point...


Just find the notes you need along the bottom E string (WHich is now tuned to F) and tune in the other strings...





F, F#, G, G#, A, Bb, B, C, C#, D, Eb, E
Reply:tune your top E string down to a B (easy because it's the same as the 2nd string). Then put a capo on the first fret... this avoids overtightening the strings.


In C++: Can a switch statement be used on strings?

No. switch statements only work on integral values or what can be considered an integral value. Which a string isn't.





Use if statements instead. Or a more complex system.

In C++: Can a switch statement be used on strings?
Nope.





The type of the switch expression must be an integral type or convertible to an integral type.

blazing star

C++: How to find the difference of 2 strings ?

For ex:


char * message = "Please answer this for me will be thankful" ;


char * substr = "Please answer this";





diff (message, substr) ;


should return "for me will be thankful";





Thanks in advance.





-Mazin

C++: How to find the difference of 2 strings ?
Here's diff





diff(char *message,char *substr)


{


/*hope the first few characters are equal*/


int len[2];


int i,l;





len[0]=strlen(message);


len[1]=strlen(substr);





if(len[0]%26lt;len[1])


{


i=1;


l=len[0];


}


else


{


i=0;


l=len[1];


}





while(l%26lt;=len[i])


{


printf("%c",*(message+l));


l++;


}


}
Reply:if you're asking if there is a function that can do that the answer is no. I'm afraid you'll will have to develope it. As I see it, seems easy. For more info klastor00@yahoo.com anytime
Reply:char *diff(char* a, char *b) {while (*a++ %26amp;%26amp; *b++); return *a ? a : b;}
Reply:rtfm!
Reply:You will have to create it yourself I think. I will guide you through it, but not supply the code.





Make a function, as you described, diff(message, substr)


Inside, the function, start a loop that stops when the first null character, signalling the end of the string, is found.


Keep a counter of how many times the loop looped.


This counter will be a position in the message for where the substr ends.


Return or print out the required substring " for me will be thankful", it should have a space at the start, as the other does not have a space at the end.


Is there a way, in the C language, to compare individual parts of different strings?

I am trying to program just a simple hangman game, and when I wanted to compare the users guess to the string which was the word, I thought this would work...





if (guess==word[i])...





with guess being their input and word[ ] being the string that is the word they are trying to guess. But my compiler had an issue with this, saying that I was passing the getche() function too many arguments. Does anyone know of a proper/better way to compare individual parts of a string to a character? Thanks.

Is there a way, in the C language, to compare individual parts of different strings?
http://www.cppreference.com/stdstring/st...


http://www.die.net/doc/linux/man/man3/st...
Reply:well you can do if(guess[i]==word[i]) ?





example:





%26lt;stdio.h%26gt;


int main() {


char buffer[256];


printf("richest man in the world: _ _ _ _ _ _ _ _ _");


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


char *answer="bill gates";





if(buffer[i]==answer[i]) {


correct execution


i++;


} else {


do w.e


}


}





I dun recommend you use this coding style tho as its messy you will end up with huge code density and it totally kills any way to expand... just wrote this to show an example and didn't even attempt to compile it... good luck.





theres also the strcmp function...





strcmp("test", input);








"But my compiler had an issue with this, saying that I was passing the getche() " %26lt;%26lt;%26lt; this has nothing to do with how your comparing the strings tho ... its complaining about getchar() having too many arguments... read the docs for getchar() an d make sure your calling it correctly.
Reply:You can use the strcmp() function to compare the entire string. However, if you need to compare parts of string, then you must remember that string in C is stored in the form of array of characters. Then you can use the loop as follows:


int streq=1;


for(i=start;i%26lt;end;i++)


{


if(s1[i]!=s2[i])


{


streq=0;


break;


}


}


if(streq) printf("String are equal');


else printf("Strings are not equal");





Remember that st1 and st2 are the two strings and start and end are the starting and ending points of the string.
Reply:of course, but using string compare function which is strcomp





for example





if (strcomp(string1, string2) == 0)


// this means if the two strings are equal





if (strcomp(string1, string2) == 1)


// this means if the two strings are not equal
Reply:its simple just use


scanf("%c",%26amp;guess);


use this statement for accepting a guess character and the program will work thank you and use the same loop and in loop use this statement


if(guess==a[i])


this will work now thank you oh and yeah the string compare function is strcmp and strcmpi where strcmpi is not case sensitive and it is not strcomp


B.C. Rich string help....?

Alright, so as you saw I have a B.C. Rich Bronze Series Warlock guitar (red). I got it a little while ago, and just today one of my strings broke. It was the e (thinnest) string. I need help with getting it replaced. I'm a beginner and this is my first electric guitar. I read online that some some strings break real easily on it, so I need a kind of string that won't =]. Can I do it by myself or should I give it to the store? If I do it myself (which I'll probably get the previous owner of the guitar to do it for me) what kind of strings should I buy? Name, place available, and price please. Thanks a lot guys!!!





P.S. I know this is silly but I have no idea what I'm doing, except for playing, with a guitar. =D

B.C. Rich string help....?
guitar strings are an acquired skill. if you stick with the guitar you will learn. depending on how long the strings have been on the guitar you may just want to replace all six.





I use d'addario (xl) with the high 'e' string (the one you broke) is a .010 gauge. have a friend help you pick them out and show you how to change them. you can do the same at your local guitar shop or general purpose music store.





if you have more break you may want to see if there is something with the frets, saddle, tuning gear or nut that is causing this problem.





good luck!
Reply:Congratulations. I myself have a Beast Platinum Pro.





Be very glad you don't have the floating tremolo. Possibly the hardest thing on earth to string until you know how.





On a B.C. Rich you can't go wrong with GHS Zakk Wylde Boomers. It'll give the guitar that drop tuned sound without having to drop tune it. You'll get a ballsier, heavier sound. Great for power chords.





I can't really help you with where to go since I'm not in your country. Do a bit of homework and find a good guitar store with a good guitar tech.


They should cost around $6-8 for the strings, no idea what setup will cost. Do yourself a huge favour and take the guitar to the store and get them to do a setup. Ask the tech to show you how to string it.





You'll end up with a better sounding guitar and you'll know how to string it right.
Reply:strings are personal preference


i prefer the GHS boomers 10-46


alot of peope like elixers or ernie ball


just gotta play different kinds and find the one you like the best


and changing a string isn't hard


the only way to learn is if you do it yourself
Reply:I used to have a BC Rich Warlock. Mine was Platinum, but I don't think that makes much of a difference. I had a real problem with the hardware, it was a soft hardware (chrome?) that kept on forming burrs in the saddle, which lead to my strings constantly breaking.





I would take your guitar to a guitar tech and ask to have it set up and intonated, and ask them to check for burrs in the saddle. I don't know if your guitar has a tremolo/floating bridge or not, but if it does and you don't know how to use it yet, ask them to block it off - this helps with sustain and helps keep your guitar in tune. Focus on learning how to play your guitar first, then introduce the tremolo when you're a little more comfortable with the basics - and your ear is trained to know when you're going out of tune.





Consider getting replacement hardware or a different guitar. I'm sorry to say it, but I have little respect for BC Rich's less expensive guitars. I got a Jackson, then an LTD, and haven't had a string snap once, versus having strings snap once a month or more with the effing Warlock - I don't even play as much as many other people do, maybe 6-8 hours a week.





Better and thicker strings will help keep you in tune and sound a little better. When you get your guitar set up, ask the tech about bumping up a gauge, if that would be right for you.





Setups can cost anywhere from 30-100 dollars, depending on what you want done. Go to a real music store if you can, go to Guitar Center as a last resort (personal experience hasn't been so good, although a lot will depend on the individual tech doing the work).





Every time you change string gauge you should get your guitar reintonated (or learn how to do it yourself) so your guitar sounds in tune all the way up the neck.








Saul


Could Musharraf be both president and C&C if the CFR and MIC put strings on him like President Bush has???

Counsel on Foreign Relations


Military Industrial Complex

Could Musharraf be both president and C%26amp;C if the CFR and MIC put strings on him like President Bush has???
Bush has cut his string and is on his own god help us

imperial

On my C drive I have folders with long strings of just numbers and letters.?

What information do these folders contain and can I safely delete them?

On my C drive I have folders with long strings of just numbers and letters.?
These are temporary folders Windows creates when doing Windows Updates. Windows puts these on whichever partition on your computer that's the biggest - for most people, usually the C drive. When you reboot after updates, Windows should get rid of these temp folders, but sometimes something will go wrong and it won't delete. It's usually safe to delete these folders, but you might want to set a system restore point beforehand to make sure.
Reply:they sound like temp folders on your drive, if you not sure then just delete to you recycle bin





in a weeks time if your machine is ok, delete
Reply:yep get rid they are old missplaced temp files of a virus eather way get rid





oh and how can deleting a file fry your pc and a real comp dude dosnt use caps lock it is for noobs
Reply:Where exactly are the folders located?





They could be temp files, which you can delete, but could also be something more important.





You might be able to open the files within the folders to have a look.





If in doubt, don't delete them.
Reply:DOOO NOT DELETE THEM YOU CAN FRY YOUR COMPUTER
Reply:That sounds like the temp files you get when doing a windows update, yeah its safe to nuke them from your Hard drive without any problems


Does C++ allow you to declare arrays of strings?

Yes.

Does C++ allow you to declare arrays of strings?
Yes.


In C++ string is array of charecter.


So array of string is indeed 2D array of charecter( or array of charecter type pointer.)
Reply:C++ doesn't have a string object built in.


The Standard Template Library (STL) has a string class and you can declare an array of those.


If you are using Microsoft C++ with MFC, you can declare an array of CString objects.


You also can define your own string class or use and array of arrays of char.
Reply:yes but you need to include a special library. I believe the following would work:





#include %26lt;string%26gt;





string myString [100];
Reply:What you can do is declare a class or a struct of a string, and then declare that class/struct as an array.





E.G.





struct MyStringStructure


{


const char* String;


/*Maybe instead:


char String[256];*/


};





MyStringStructure* g_StringArray;





There are also other ways of doing this, but this seems like the best. I also believe that Microsoft C++ has integrated some sort of string class, but it is very difficult to use from what I understand.


On a guitar how are the strings labeled such as a b c d e f g?

E A D G B E





fattest to thinnest.

On a guitar how are the strings labeled such as a b c d e f g?
e


B


G


D


A


E





Im not sure if this is what you are talking about. But the way I remember it is from a cd called the jimi hendrix experience, it was a cd to learn how to play the guitar. "easter Bunnies Get Down At Easter"
Reply:the thickest one is low e. then going down they are a, d, g, b, e, the other e is a high e.
Reply:depends on the tuning





from thickest to thinest:


standard is EADGBE


drop d is DADGBE


drop c is CGCFAD


and standard b tuning is BEADF#B


there are a lot of ther different tunings as well those are only some.......i usually play in standard or drop d


and my one guitar is set to b tuning
Reply:yeah its such as that





EGBDF
Reply:the normal way is e b g d a E(bottom to top) but you can tune in anyway you want


In c++ how can i read spaces in strings using the >> operator?

example :


the user input is: "firstName lastName"

In c++ how can i read spaces in strings using the %26gt;%26gt; operator?
Setting skipws in your istream will let you do what you want:





string a, b;


cout %26lt;%26lt; "enter two words: ";


cin %26gt;%26gt; skipws %26gt;%26gt; a %26gt;%26gt; b;


cout %26lt;%26lt; a %26lt;%26lt; "," %26lt;%26lt; b %26lt;%26lt; endl;





skipws is set for cin by default, so unless you set noskipws for cin, you could get the same result with:


cin %26gt;%26gt; a %26gt;%26gt; b;





A more general purpose technique is to use getline:





string s;


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


getline(cin,s);


cout %26lt;%26lt; s %26lt;%26lt; endl;





so you get the whole string, with any number of words. Then, of course, you have to do some work to parse it.

elephant ear

Can a super light gauge strings handle a drop d and c tunings?

I've always used extra-light strings on my acoustic guitars. I've only done tunings a few times and most of that was open E tuning. I did occasional experimentation with other tunings, and never had a problem with extra-light strings. I can't say if these were drop D and C tunings, however.


In C, how can I read from a text file and put strings separated by tabs (\t) into a structure array?

Example:


John (\t) Doe (\t) Jr.


Johnny (\t) Doey (\t) Sr.


in an array...


typedef struct person {


name


sname


stitle


} person;





I need to do this in order to alter these strings.

In C, how can I read from a text file and put strings separated by tabs (\t) into a structure array?
Haven't been doing much C lately, but take a look in your standard io (stdio.h) and string (string.h) libraries for functions like fopen, fgets, and strtok...





That should get you going in the right direction.


Are there any viola pomposa's in existence or still made today? (5-string cello [C-G-d-a-e'] invented by Bach)

The International Music Co. (NY) edition of J. S. Bach’s Solo Cello Suite #6 in D was “composed originally for an instrument with 5 strings C-G-d-a-e', 'Viola Pomposa' which was invented by J. S. Bach". (1) Are there other historical references to this instrument? (2) Are old instruments still in existence? (3) Do modern makers still make it? (4) What string length, string gauges and string materials do they use? (Shorter length is needed so the high e’ string won’t need to be tuned so tight, but the shorter length for the lower strings means they need to be tuned looser, thus lack volume and sonority.) (5) How will the body and neck support the added tension of the extra 5th string? (6) What is the proper width, length and depth of the instrument body for the best resonance and sonority? (Will the instrument sound like a high-pitched cello or like a low-pitched viola?) (7) Would a 4-string version (G-d-a-e’) add anything to the String Quartet, Cello Quartet or Cello Orchestra?

Are there any viola pomposa's in existence or still made today? (5-string cello [C-G-d-a-e'] invented by Bach)
There are modern 5 string cellos with C,G,D,A,E, tuning, mostly of the electric variety. These are mostly used in non-classical groups. Having the hogher register available adds to the ability of the cello to carry more of the lead and melody lines, as opposed to its more traditional supporting role. There was also an instrument in the mid 1800's called the Arpeggion. Franz Schubert wrote a sonanta for that instrument. http://en.wikipedia.org/wiki/Arpeggione





This instrument is not being currently used much either.
Reply:The only thing I know of that sounds close is a five-string violin/viola. I had a friend in college that had one - it was pretty cool even though it was electric. I've seen others and they have all been electric. It had c-d-g-a-e strings and sounded like a viola/violin as it had the range of both instruments.





As for other old instruments - I've seen and played dulcimers, psaltries, zithers, and knew a guy who made a hurdy-gurdy.





As for the rest of your questions, sorry I can't answer them. I suggest that you find a good luthier in your area and ask him/her - or if there's a college with a good music program - ask a music history professor there.
Reply:I can only confidently say that it is unlikely that this instrument would add anything to the string quartet because the string quartet came in later. I've never come across this instrument but there are many collections of historical instruments that could have one. Here in Britain we have the Royal Academy of Music in London, and the Victoria and Albert musuem sometimes has old instruments. This sounds like it might be a relative of the viol, and there are still examples of that around.


Consider strings of length 7 formed from the letters a,b,c,d,e,f,g (wthout repetition)?

how many of these strings do not have the letters f and g appearing together?

Consider strings of length 7 formed from the letters a,b,c,d,e,f,g (wthout repetition)?
I'll assume that by "appearing together" you mean that f and g are adjacent. Thus, "bagfcde" would be called "appearing together," and "fcgeadb" would not.





It's easier to count the number of strings that have f, g adjacent. First we count the number of strings that begin with fg and are followed by any permutation of a,b,c,d,e. There are 5! = 120 of these.





Next, we allow "fg" to appear at any position in the string. We have 120 strings of the form "fg.....", 120 of the form ".fg....", etc., up to 120 of the form ".....fg". So we multiply 120 * 6 to get 720 strings so far.





Finally, for each string of the form "..fg...", there is a string of the form "..gf...". So we multiply 720 * 2 to get 1440 total strings with f,g adjacent.





So the number of strings without f,g adjacent is 7! - 1440 = 5040 - 1440 = 3600.
Reply:if you have 7 letters and 7 positions of non-repeatative numbers, then your answer must be zero because all strings of lenght 7 will contain the letters
Reply:The answer is 3600





Number of strings of length 7 = 7! = 7x6x5x4x3x2x1 = 5040





If we imagine there are 7 positions, then f and g can be next to each other in the 1st and 2nd positions or the 2nd and 3rd or........or the 6th and 7th. This makes 6. But since f and g can be in the order fg or gf, then the total is 12. Now for each of these 12 positions, the remaining 5 positions can be filled by the remaining 5 letters in 5! = 120 ways. So there are a total of 12 x 120 = 1440 strings with f and g next to each other. So the answer to your question is 5040 - 1440 = 3600.
Reply:With F as your first letter, there are 5 possible letters to be second (any except G) and 5! possibilities for letters in positions 3-7.


With F as your last letter, there are 5 possible letters to be sixth and 5! possibilities for letters in positions 1-5.


2 · 5 · 5! = 10(120) = 1200.





With F somewhere in the middle, there are 5 possible letters behind it (any except G), 4 possible letters after it (any except G and the letter before F), and 4! possibilities for the letters in the remaining positions. There are 5 possible placements for F in the middle.


5 · 5 · 4 · 4! = 100(24) = 2400.





There are [1200 + 2400 =] 3600 ways to arrange the letters A through G such that F and G don't appear next to one another.

lady palm

In C, how are spaces entered in strings entered from user?

[%s in scanf does not consider spaces]

In C, how are spaces entered in strings entered from user?
you can read a whole line with fgets
Reply:Use "gets"... but you will have to parse the string yourself.





#
Reply:Use gets( char * ), gets reads until a newline is found. Note that the newline (\n) is not returned in the string.


C# simple shop pricing programme; using strings and arrays?

Your question is quite confusing, but you can get your programming needs met here http://www.dimdigital.com


What does # mean when reading guitar tabs and why when reading them is there sometimes a 'C' string??

i dont have a c string ???

What does # mean when reading guitar tabs and why when reading them is there sometimes a 'C' string??
that would be a sharp note. one step higher than the note with out the sharp. :)
Reply:# is the sharp symbol
Reply:Ofcourse there's a C string...and # means sharp
Reply:a C sharp
Reply:Sharp Note. Usually up from a white key to a black key on a piano
Reply:I would assume that # means the same thing as it does in any musical notations - sharp, i.e. a half-tone up.
Reply:#: Sharp


♮: Natural


b: Flat
Reply:It's a sharped note; it means that you raise the pitch by a half-step (one fret, on a guitar).
Reply:No such thing as a C string so the letter is an indication of the chord. The # sign indicates a sharp note which is one fret higher than its usual position and the b sign indicates a flat which is one fret lower than the usual position. The Natural Sign is only used when a note has been sharped or flatted and needs to return to it's normal position within the same measure or between two bar lines OR when a note is sharped in the key signature and the notation requires it to be played in it's usual position. Of course these rules apply to musical notation on staff paper and not in the Tablature notation method.


You can browse through some of the offerings at ehow.com for "how to read guitar tablature" and see if you can pick up some new pointers.


Here is the link: http://www.ehow.com/Search.aspx?s=guitar...
Reply:sharp note


How can we store strings in an array in c?

that is, getting 3 names like john,david and deny using "for" loop then storing these names into an array using the same "for" loop.


simply getting and storing names will be done in the same "for" loop in any method like without using pointers.i've a doubt is there any method to getting and storing names in "for" loop without using pointers?if so please explain me........

How can we store strings in an array in c?
You may want to buy K%26amp;R's "The C Programming Language" which is the standard book for C programmers. They cover C strings. I'll point you to an online tutorial (http://www.cprogramming.com/tutorial/c/l... ).





There's two ways you can have a string. You can either have a pointer to a string literal, or have an array (either a pointer to one or the array object itself).





You may want to lookup the C standard library to see what you can use for input. (http://cppreference.com/stdio/index.html... The fgets function is particularly useful for this. If you look at the tutorial I pointed you to, they mention how to use it.
Reply:You can do it with a fixed-size array of char* s:





char* MyArray[ 3 ];





But no, there have to be pointers involved.

snow of june

C Passing a 3-D array of char strings to a function?

So I have a 3-D array of char strings -


char* val[256][256][256];





I need to pass a reference of this to a function, how do I do this?


If it was a single array I can pass it as follows


char* val[256]


func(val);


....


void func(char** a){}





However


void func(char**** a){}


doesnt work.





Any suggestions?

C Passing a 3-D array of char strings to a function?
int stPar (char a[5][5][5])


int stPar2 (char *a[256][5][5])


------


both of this work fine.


=====================================


Some thing to know more is in C





char *a;


char b[256][256];


a = b;





Works just as fine. The multiple index only indicates amount of memory. You can still pass as char * and then assign to deceleration as 3d array and it will work fine.


Can any one of you solve this programm in C++, if P & T are strings with lengths R & S repectively?

And are stored as arrays with one charecter per element , find the indedx(location) of P in T??

Can any one of you solve this programm in C++, if P %26amp; T are strings with lengths R %26amp; S repectively?
Basically you have a couple of indexes





index_in_P


index_in_T





They both start at the beginning. You use a main for loop to walk through T.





if P[index_in_P] == T[index_in_T]


start seeing if the string matches all the way


for the rest of the letters in P (up to length R)


if P[index_in_P] == T[index_in_T+index_in_P]


you are still matching, good, increment index_in_P


else


they no longer match





index_in_T only increments when you are looking for a new start letter, it is the index you will return. If it is possible P is not in T, you need to make sure you don't go out of bounds in T.
Reply:Heres the C way:





int i, j;


for (i = 0; i %26lt; S - R; ++i)


{


for (j = 0; j %26lt; R; ++j)


{


if (P[j] != T[i+j])


break;


}


if (j == R) // got to the end of the loop successfully


break;


}


if (i == S - R) // got to the end without finding P in T


printf( "not found\n" );


else


printf( "found at %d\n", i );





In C++, I would use the string.find function:





size_type pos = T.find( S );


if (pos == npos) // npos is a constant


cout %26lt;%26lt; "not found" %26lt;%26lt; endl;


else


cout %26lt;%26lt; "found at " %26lt;%26lt; pos %26lt;%26lt; endl;





The more verbose way would be to use string.substr:





int pos;


for (pos = 0; pos %26lt; S - R; ++pos)


{


if (T.substr( pos, R ) == P)


break; // found it


}


if (pos == S - R)


cout %26lt;%26lt; "not found" %26lt;%26lt; endl;


else


cout %26lt;%26lt; "found at " %26lt;%26lt; pos %26lt;%26lt; endl;





And the most generic way using a C++ algorithm template:





char * pos = search( T, T+S, P, P+R );


if (pos == T+S)


cout %26lt;%26lt; "not found" %26lt;%26lt; endl;


else


cout %26lt;%26lt; "found at " %26lt;%26lt; (int)( pos - T ) %26lt;%26lt; endl;


What is the meaning of STRING in C?

What is C string? Can you please provide me good and exact answer. Thank you so much.

What is the meaning of STRING in C?
If you want to know how to work with it then search for some documentation. There you will find a lot of functions and operations.
Reply:An array is a data type that stores data in sequential memory slots.








A string is an array of characters.
Reply:A STRING, in essentially all programming languages, is a type of variable or constant which stores a series of alphanumreic characters, as opposed to an INTEGER which stores a number without a decimal and BOOLEAN which stores a 1 or a 0, a true/false value.


Plz solve this programm in C++, if P & T are strings with lengths R & S repectively and are stored as arrays?

with one charecter per element , find the indedx(location) of P in T??

Plz solve this programm in C++, if P %26amp; T are strings with lengths R %26amp; S repectively and are stored as arrays?
@P and @T ??
Reply:then u put in the oven to bake for half an hour lala x

sweet pea

Plz solve this programm in C++, if P & T are strings with lengths R & S repectively and are stored as arrays?

with one charecter per element , find the indedx(location) of P in T??

Plz solve this programm in C++, if P %26amp; T are strings with lengths R %26amp; S repectively and are stored as arrays?
loop through P %26amp; T until you find the character you're looking for, add 1 to "currentIndex" starting from zero each time through the loop, then return current index.
Reply:i dont think that there is any datatype say string however u can use char arrays oooh u mention arrays hope u r refering the same then








there are many cases to handle


for eg if R%26gt;S then u never find P in T however reverse is possible (hope u got my idea)





is P bigger than what T holds ??





and if all checks verify the possibility that P can be found in T then create an integer variable say index , set it to Zero and start searching char by char if the first char match incriment some pointer var say point=1 and increment till it matches the subsequent chars in T of P if it fails (means within point reaches the length of P it trace uncomman char then simply jump to index+point bcz u didnt find the match there and continue searching.....





if u reach the index %26gt; (T.length - P.length) (bcz after that u cant find P in T :-) means u dint find the string display sorry else if u finde in between make sure to toggle a flag variable so that after that loop u can trace that u find that string and u can also make a variable say counter =0 to check how many time u get that string.......





hope u get the best 4m me


in last plz rank my answer as best if u feel so


and comment plz :-) i m waiting





well as d below person use pointers and provide u d code i think it can be easily done by array indexing as i mention above and y he give d code it must let u first exercise yourself n then if cant implement then only code is given to you however, u r looking smart and i hope u can implement it by your own with my logics





good luck n great fun





http://www.geocities.com/ankur899/
Reply:Doing a homework assignment?





int (const char *p, int r, const char *t, int s)


{


int i;


for (i = 0; i %26lt;= (s-r); ++i)


{


if (strncmp(t+i, p, r) == 0) return (i);


}


return (-1); /* not found */


}





Of course, this is C, but C is a subset of C++, so this would work. I don't remember C++ has an exact replacement for C's strncpy() other than those that use the String class. But as you state your question, String probably isn't allowed.





To answer a comment by "d person above," please note that, in C, arrays and pointers are interchangeable in use. It's the declaration that's different. In particular, many people don't realize that *(a+i) is exactly the same as a[i] in C and C++. Exactly, as in by definition. That leads to the rather strange result that a[i] is exactly the same as i[a], even if 'i' is an int and 'a' is a pointer or array!





Anyway, certainly you can find harder ways to solve this problem by doing more of the work yourself. But this is the simplest way.