Sunday, July 12, 2009

When writing C++ do you need to memorize the strings and names ?

What else do you need to memorize when writing C++ ?


Thanks

When writing C++ do you need to memorize the strings and names ?
%26gt; When writing C++ do you need to memorize the strings and names ?





You shouldn't approach C++ from the point of memorization. You'll remember just from practice and experience.





It's better to find a good resource to look up the standard library, such as Dinkumware's reference, or cplusplus.com or cppreference.com . Or one of the high quality books out there, like The C++ Standard Library.





You'll want to know the C library as well. You shouldn't draw a blank when you see printf, or scanf, or fgets, fprintf, strtol, and so on. They are used so often in C that C++ programmers should know them as well.
Reply:The only thing you really need to"memorize" is the syntax of the language. You let your program "remember" (using variables and constants) or point to (using pointers) strings. Then you use the language to manipulate those strings. By "names" perhaps you mean the names of those variables and pointers?
Reply:what means that memories?


i do not know,,


with my understand ,,


no need to memoties ,,


if u work more hours then it should be in ur mind ,,,


no need mugup.ok


just do practical...


that is enough...


no need to memories,,,


do well


all the best

bottle palm

Using C++ String manupulation...Help?

Using C++ how can I receive a string input given below:





User input: (First Name) (Last Name)





Then Print out:





Output: (Last Name) , (First Name)

Using C++ String manupulation...Help?
your getting a user input for first and last name seperated by a space. use the strtok() function to extract the strings on either side of the space. then print it in the format you want.
Reply:Its easy.


Use space as a delimiter. Scan the string from left to right whenever you encounter the space overwrite it with a NULL and go to the next position in the string and copy it in a new string till the end of the original string is encountered. When the end of the string is encountered put a space and after the space a NULL. Then concatenate the original string with this new string. Then you will get your answer.





I have told you the logic now its up to you to do the coding. I can do the coding but you must do your homework yourself.


Write a program using a C-string in C++?

Write a program that asks the user to enter a single digit numbers with nothing separating them. Read the input as a C-string. The program should display the sum of all the single digit numbers in the string....


For example, if the user enters 2514 the program should display 12, which is the sum of 2, 5, 1, and 4.


The program should also display the highest and lowest digits in the string.

Write a program using a C-string in C++?
Take a stab at it, and see if we can help with the code. Doing your own homework is good for you.
Reply:May be you can post your requirements at http://homework.ccietutorial.com/


and let many programmers bid for your project.


You can hire whoever you like.





Do not pay any money afront however.


Have any women tried the c-string?

haha i could not wear one! a thong, sure, the g-string, maybe! but you won't catch me in that little thing.





http://www.c-string.co.uk/images/cstring...


http://img.auctiva.com/imgdata/2/2/0/7/8...


http://img.auctiva.com/imgdata/2/2/0/7/8...


http://www.c-string.co.uk/images/cstring...





(the pictures are kind of revealing, not too much but yeah kids don't click)

Have any women tried the c-string?
Oh my god I would be scared that it would drop down. Could you imagine that at a party. Not for me. Ill stick to my thongs and g strings. Cheers
Reply:Cute but not for me





I'll stick to my thongs.
Reply:those r the best thing ive seen, but i dont think they would be very comfortable.
Reply:How on earth does that even work?
Reply:Now we know how they use that part they take out of the crotchless panties
Reply:A lot of women wouldn't even bother since it would require an effort in trimming down there.
Reply:I dont know how that stays on. But, I think thats for strippers.
Reply:Those are weird. How do you keep it in place?! No, I would never wear one of these.
Reply:how do the even stay on!,i would never wear one,looks way too uncomfortable
Reply:wow .. that looks very uncomfortable.. i wouldnt wear one either
Reply:Well HELL!!! does it stick on like a pad???????????? It looks not finished.


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

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





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


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


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





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

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


char string2[256];





cin.getline(string1, 256);


cin.getline(string2, 256);





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


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


}


else{


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


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





bool CheckTwoStrings(char* str1,char* str2)


{





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


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





while(*str1!='\0')


{


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


str1++;


str2++;


}





return true;





}





int strlen(char *p)


{


int i=0;


while(*p!=0)


{


i++;


p++;


}


return i;


}





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


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


Hope this helps!


Good Luck!

magnolia

How do I convert a c-style string of chars into a c++ style string of chars?

I'm getting a file name from argv and I need to use that file name to open the file using ifstream and get the contents of that file. But I'm having trouble compiling.. I have





string fileName(argv[1]);


ifstream myfile(fileName);


if (!myfile)


exit(1);





It compiles if i make it


ifstream myfile(fileName.c_str());


but I dont think it's what I want. Is there a way to make the fileName into a c++ string?

How do I convert a c-style string of chars into a c++ style string of chars?
Derive the class ifstream so that you can use string as a parameter in the constructor as well as char*.





eg.


class inputstream : public ifstream


{


public:


inputstream(string s)


: ifstream(s.c_str()) {}


}





This will make it what you want.
Reply:use argv[1] instead of fileName.


C# string recognized as variable?

In javascript there is the eval function but how would I do the following in c#?





int myInt=2;





public void changeToVar(string toConvertToVar)


{


int mySecondInt=SomeFunctionOrMethod(toConve...


Response.Write("The result is: "+mySecondInt);


}





changeToVar("myInt");





output:





The result is: 2

C# string recognized as variable?
http://www.odetocode.com/Code/80.aspx
Reply:i don't really understand what you want to do here but the line





changeToVar("myInt");





you declared myInt as integer variable but your passing it as a string. to get the result 2 you should change it to





changeToVar(myInt);





hope this helps in someway...