Monday, May 24, 2010

Which strings are best for the G and C Strings on a Cello?

My teacher recommends me to switch the lower strings on my cello because it doesn't match the sound well. I currently have Helicore. Which is the best or a good one to choose from?

Which strings are best for the G and C Strings on a Cello?
Personally I think Helicore strings are the best, but if your teacher wants youto get new strings you should try gettind Dominant strings





hope this helps


Can you help me a problem in arrays of strings in C?

How can I copy a string (array of character) to an array of string such as:





char text[a][b];





wherein a is the index number of the array and b is the max length of array of characters that can be stored in the array..





For example I have an array of characters "char word[20];"


How can I store it to an array of strings "char text[99][20];"??





Please help.. And thanks..

Can you help me a problem in arrays of strings in C?
you can use the strcpy() function.





strcpy(text[99], word);





or:


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


{


text[99][a] = word[a];


}





both will work.
Reply:Yes it is possible!!


Wat U need to do is that for example


let








char word[5]={'a','b','c','d','e'};


char test[20][10];


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


{ {test[p][q]=word[i];


q++;}


if(q==10)p++;


}








Ok Gud LC Bye
Reply:for (int x=0; x%26lt;20; x++)


{


text[0][x] = word[x];


}





// This will copy the char array word into the first row in text.


// word is a one dimensional array.


// text is a two dimensional one.


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

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


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

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


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





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





Rawlyn.
Reply:yes indeed

baseball cards

How to check for anagrams in C++?

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





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





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





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

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





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





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





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





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





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





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


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


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


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


{


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


break; // we're done


}








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





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





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





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





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





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





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





then print results.. eg..





found =


not same letters =





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


How do i know if my bass is tuned to C correctly?

i just tuned my low e string to C so it would sound better when playing SOAD seeing as how most of there songs are on only one or two strings.


its tuned to C but its really loose and buzzes off the frets so im not sure if its right

How do i know if my bass is tuned to C correctly?
If you're going to tune down that far, you'll need thicker strings, and possibly a neck tweak.


Java equivalent to System.Text.StringBuilder in C#?

I want to build a very large string from lots and lots of small strings. In C# I would use System.Text.StringBuilder without hesitation. At present I am using java.io.StringWriter, but I am concerned that it may not be efficient enough? Is there a better option? MUST be FAST! Thanks in advance.

Java equivalent to System.Text.StringBuilder in C#?
That is not what StringWriter is for. StringWriter is a character-based output stream that writes the bytes to memory.





Use java.lang.StringBuilder. It was added in Java 5 (JDK 1.5). It is similar to java.lang.StringBuffer, but without the synchronization. So, if you plan on designing your program such that only one thread will be using it, use the StringBuilder.


C - How do I save data in a text file?

I have made a maze game in C and am stuck on how to get a user name and save the username and score on a text file. I don't know much about string in C except that "it is an array of characters". I know a user name will need to be string so I am using this:





char username[3];


scanf("%s", username);





I am assuming the variable 'username' will be saved to a file but I do not know how to do this. Any ideas?

C - How do I save data in a text file?
You need the following basic steps:





FILE *fp; //create a file pointer


fp = fopen("file","w"); //open "file" for writing "w"





//check if the file was opened without errors


if(fp==NULL) {


printf("\nCould not open file.. aborting!!");


exit(1);


}





//write to file - you have a number of options here - read more about the functions to suit the formatting and data you need to write to file - one example below:





fprintf(fp, "%s %d", username, score)





fclose(fp); //close the file pointer once you are done writing to the file.
Reply:Use fprintf() function or fwrite() function. Refer the page given below...

artificial flowers

Question about strings in C?

When reading in strings, how can I include spaces in the string?





What I mean is that, normally, you'd need something like





scanf("%s%s%s", %26amp;str[0], %26amp;str[1], %26amp;str[2])





to take something like





"one two three"





and read it in as three strings.





How can I read in "one two three" as one string? That is, without the program assuming that spaces are breaks between strings?

Question about strings in C?
You can use scanf as below to read until end of line.





scanf("%[^\n]",%26amp;str[0]);





That should work.





All the best !
Reply:fgets gets the entire line.


If you want to read in more than a line you must use fread.


Then parse it manually.





P.S.


I personally don't use scanf to read in strings from stdin because it's a potential buffer overflow(security risk).


If you are going to use scanf specify the field width %10s or use %as to allocate the string.ualifier is present, the next pointer must be a pointer to


wchar_t, in


C programming question?

Given the following declarations:


char a[ ] = "abc", *p = "def";





What is the effect of the following statement?





p=a





a. It copies the string "abc" into string p





b. It changes p to point to string "abc"





c. It copies the first character of a ton the first character of p





d. It generates an error

C programming question?
haha cheater.





ya D) is looking good.
Reply:Genrates Error
Reply:b.


p is a pointer to char.


The name of the array a is also a pointer to char.
Reply:b. p will point to a which contains "abc".
Reply:The answer is b.





I just wrote a little code to do it, although I should have been smart and just looked at K%26amp;R.
Reply:p will then point to the first position of a, it won't point to the whole string but you can use pointer arithmatic to get the rest of the string. So - E. none of the above.
Reply:Usually it would be b. Because you replaced the adress the pointer points at. But i am not quite sure you can declare a pointer on a string constant (*p="def") - it would probably generate an error.


How do you reverse a string? In other words if I have "It is hot today", I want to get "today hot is It".

How do you reverse a string in C/C++?

How do you reverse a string? In other words if I have "It is hot today", I want to get "today hot is It".
hmmm, sounds like you should read your text, perhaps post some code and then ask for some help. this might lead you in the right way:





#include%26lt;iostream%26gt;


#include%26lt;string%26gt;





int main()


{


using namespace std;





string txt;





cout%26lt;%26lt;"Enter anything, come on, anything...\n";


getline(cin,txt);


string::iterator end = txt.end( ) - 1;





for( ; end != txt.begin( ) - 1; end--)


{


cout %26lt;%26lt; *end;


}





cout %26lt;%26lt; endl;


system("pause");


return 0 ;


}
Reply:just reverse the string i guess


and in arrays if it from 1 to 5 it will count 12345 but if u reverse it as 5 to 1 , it will show 54321


good luck
Reply:Technically you are not reversing a string. You are reversing a subset of items inside a string.





So you would have to create an array of strings. Parse the contents of your original string by some separator, such as a space.





Then just reverse loop through the array of strings.


How can i manipulate string to know whether the substring is contained in the string?

how can i manipulate string in c++ to know whether the substring is contained or have a pattern in the string?


but,without using strcmp.

How can i manipulate string to know whether the substring is contained in the string?
Saw this yesterday...
Reply:in C/ C++ i would go for the library function strstr();


in JAVA, str.contains(str1) would do the trick, where str is the string in which str1 has to be searched

800flowers.com

C++ Pointers to Strings?

I'm writing a C++ program in 3 separate files. Here's some of the pseudocode:





Rectangle.h


_________





...


private *char name;





rectangle


deconstructor


getName


setName


draw











Rectangle.cpp


_________





default constructor: name = "bleh";


constructor: [asks the user to enter a name and prints it back]


draw: [print name]


getName: gets the name


setName: modifies the name


deconstructor: deletes the string








TestRectangle.cpp


___________





...


Rectangle r1;


r1.draw();


r1.getName();





How do I... er... do all of this? I have to allocate memory for the string using the new keyword.


I've been trying to look this stuff up but can't seem to find anything helpful.

C++ Pointers to Strings?
"Algorithms + Data Structures = Programs", by Wirth.





You evidently learned C++ before you learned programming. Take a break and learn programming now.


C++: Converting unsigned int to int?

I want to perform a little calculation using a length of a string in C++. Im new to this. :(





Example:





string myString = "Hello";


int myCalc;





myCalc = 100-(myString.Length); // is this correct? I want to minus string's length from 100.





But it gives compile error: "error C2440: 'type cast' : cannot convert from 'unsigned int (__thiscall std::basic_string%26lt;char,struct std::char_traits%26lt;char%26gt;,class std::allocator%26lt;char%26gt; %26gt;::*' to 'int'


Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast"








I tried casting with "int(myString.Length)" but it doesnt work. :(





Please help me out.

C++: Converting unsigned int to int?
length in standard C++ is a function. You need to call it using myString.length()





There shouldn't be a problem putting an unsigned int into an int variable. The compiler is probably complaining that you're trying to convert a function (length) into an int, since you left out the parentheses.
Reply:thanx others too! Report It

Reply:I haven't learned C++ yet( opertune word there is yet) but in Visual Basic when you want to utilize a Str varialble and a Int variable you must declare them seperately and then use the


Val() option to translate. this will allow you to set arguments for converting string varialbes to integer or vise versa.





example intcalc = Val(strCalc)





dont know if that works or if it is even support in C++ but it never hurts to take a look.
Reply:try making myCalc unsigned...


unsigned int myCalc...might work!





Additional details(added later on)


man o man


1) there is nothing that is Length it is length (C++ is case sensitive)


2) it is function so correct call would be myString.length()





then it runs on gcc compiler





best of luck!
Reply:C++ I managed to avoid thus far, but I think AM post's is correct. Make myCalc an unsigned int.





I don't know how many bytes an int type in C++ is, but for the sake of illustration, lets say it is 1 byte.





An unsigned int can take on the values 0..255


Int can be -128..0..127.





Obviously you cannot stuff an insigned int into an int. The type cast can't help you because you run into the same problem. It can't map the silly things.





-Dio
Reply:You want to cast using "(unsigned int)", like this:





myCalc = 100-(unsigned int) (myString.Length);





Now, if you change the declaration of myCalc to





unsigned int myCalc;





you could avoid the whole issue. However, if the string length is greater than 100, you'll get a very large number as a result, which could be bad.


B.C. Rich Warlock strings 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 strings help...?
ok heres the deal...


you can buy new strings and do it yourself its really easy


you want to get a first string "e" with the gauge size being "9" %26lt;---IMPORTANT! also look into a stringing tool. they're really cheap and worth the money. they make stringing a guitar really easy instead of turning the peg by hand (hand cramps suck).





BUT! Heres The Problem. You Need To Find The Same Brand That Comes On Your Guitar. Obviously B.C. Rich Strings.


They're Strings Tend To Sound Different Than Others. You're Best Option To Get The Best Sound Out Of Your Guitar Is To Either Buy A New B.C. Rich "E" String Or Buy A Whole New Package Of Strings Which Really Isnt A Bad Idea.


It Is Good To Change Your Strings Every Once In A While





Good Brands To Look For Would Be "Ernie Ball", "Elixir", And Of Course B.C. Rich. Remember To Get 9 gauge Strings
Reply:ernie ball bad they will break blue steel are great but there steel they will wear your frets faster if you realy want some good strings elixer they are 13 dollars tho but great tone Report It



C/C++ pointers as strings?

I am a relative novice at C++, and I am trying to write a stack class that holds lines of text. I need to hold everything in pointers because I don't know the sizes of things, and I have one question. Do you have to use new or malloc to allocate adequate memory to a pointer, or will it act intelligently? For example will:





char *string = new char;


std::cin %26gt;%26gt; string;





instead of:





char *string = new char[100];


std::cin %26gt;%26gt; string;





possibly cause it to segfault or corrupt other variables (I know it will at least hold the data)? I haven't had that happen before, but just to make sure...

C/C++ pointers as strings?
the above answer is excellent advice (or below, the guy who said use strings). Do NOT use arrays of chars. You risk buffer overflow and if that happens your program will be entirely compromised. A buffer overflow in your case would be when you had a char array of say 100, but the user entered a line of text with over 100 chars. After 100, you're program will be writing char values to memory that is outside of your array and could be other variables, return values, etc.
Reply:Hi,


If u r using char pointers then dont worry about the size of string, to be saved in that char pointer.





Poiter reuires 2 bytes only. Char pointer holds only the address of the string not the string itself.





so


char *p;


p="a";


or


p="abcdefghijklmnopqrstuvwxyz";





so either u save a character or a string of any length, doesnt matter.
Reply:These examples do not make sense to me. 'char' is a primitive type and not a class.





This is how I would declare string. It is a simple array of char big enough for what you will use it for.





char string[100];


std::cin %26gt;%26gt; string;





If you use the C++ string class then it will resize and do clever things automatically. Hurrah!





#include %26lt;string%26gt;





string mystring;


std::cin %26gt;%26gt; mystring;


std::cout %26lt;%26lt; mystring;

wildflower

I need add 2 string in VB 6.0?

Dim a as string


Dim b as string


Dim c as string


a="HI"


b=" "" "


c=a+b


How i show c="HI"


I can not add "" (this string). Pls help me

I need add 2 string in VB 6.0?
Dim a as String


Dim b as String


Dim c as String


a = "HI"


b = "!"


c = a %26amp; b





would make c = HI!





Is that what you're asking?


What is the c++ code runnable in dev c++ developmental tool, for this output????

what is the c++ code runnable in dev c++ developmental too, for this output????


it will accept a string and creates a figure,, like in the following:





(it will be like this if the number of amount of string is an even number)





enter string: ccss


c c


c


s


s s





(it will be like this if the number of amount of string is an odd number)








enter string: table


t t t


a a


b


l l


e e e








(note: it should be 3 strings to be accepted as input(string) in this program)

What is the c++ code runnable in dev c++ developmental tool, for this output????
what he heck is this? where did you find it


C++ Programmers!! help!!?

there's an error in this code... can you help me repair it?!








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


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


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


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





void initval();





int chars[255];





int main()


{


FILE *file_r;


int ferr = 0, i;


char filename[50];


while (ferr == 0)


{


system("cls");


printf("Enter file name: ");


gets(filename);


file_r = fopen(filename, "r");


if (file_r == 0)


{


printf("Error! File does not exist!");


getch();


}


else


{


ferr = 1;


}


}


char *r;


char c, ctr = 0;





while ((c = getc(file_r)) != EOF)


{


ctr++;


}





fclose(file_r);


file_r = fopen(filename, "r");





char string[ctr];





i = -1;


while ((c = getc(file_r)) != EOF)


{


i++;


string[i] = c;


}





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





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





//tig-ihap





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


{


chars[string[i]]++;


}





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


{


if (chars[i] != 0)


{


printf("%c = %d\n", i, chars[i]);


}


}





getch();





fclose(file_r);


return 0;


}





void initval()


{


int i;


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


{


chars[i] = 0;


}


}

C++ Programmers!! help!!?
do this:





char [] string = new char [ctr];








and don't forget





delete [] string





at the end to free up the memory
Reply:from the code you provided i copy and paste it on my system and i recieved no error messages and the program ran fine most likely it has to do with your compiler in my unix based system it didn't recongize the conio.h header file try using a different compiler
Reply:you cant declare a char string that way (char string[ctr]). the length of the string has to be a constant size such as "char string[20];". as the other person said, you could also do this "char [] string = new char [ctr];"
Reply:The code you're using isn't C++, it's just C. It'd help if you listed the error.


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

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

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





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





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





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





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

tarot cards

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

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

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


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


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


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


'\r' by itself does not get translated.


outf.write(data, data_size);


outf.close();


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

Say I have the string





NewYork;NewJersey





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





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





Can anyone write a small program that will do this?





Thanks in advance!

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


// StrT: Type of string to be constructed


// Must have char* ctor.


// str: String to be parsed.


// delim: Pointer to delimiter.


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


// empties: Include empty strings in the results.


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


template%26lt; typename StrT %26gt;


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


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


{


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


char* r = NULL;


r = strstr(pstr, delim);


int dlen = strlen(delim);


while( r != NULL )


{


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


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


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


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


{


StrT s(cp);


results.push_back(s);


}


delete[] cp;


pstr = r + dlen;


r = strstr(pstr, delim);


}


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


{


results.push_back(StrT(pstr));


}


return results.size();


}








Examples:





// using CString


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


int i = 0;


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


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


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


{


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


results[i].ReleaseBuffer();


}





// using std::string


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


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


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


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


{


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


}





// using std::string without empties


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


stdResults.clear();


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


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


{


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


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





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


????





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





# include %26lt;iostream%26gt;


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


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





int main (void)


{


char str[ ] = "NewYork;NewJersey;


char *pch;





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





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





return 0;


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


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


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





int main()


{


char YourString[]= "NewYark;NewJersey";


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





int i=0;





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


{


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


{


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


break; // and break the loop


}


else


{


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


i++; incres index


}


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


getch()


return 0;


}





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





Thanks


What is the c++ code runnable in dev c++ developmental tool, for this output????

What is the c++ code runnable in dev c++ developmental tool, for this output????








(it will be like this if the number of amount of string is an even number. and prints like a shape of a hour glass)





enter string: ccss


c c


c


s


s s





enter string: ccss


c c


c


s


s s





(it will be like this if the number of amount of string is an odd number)








enter string: table


t t t


a a


b


l l


e e e








(note: it should be 3 strings to be accepted as input(string) in this program)





Additional Details





1 week ago


What is the c++ code runnable in dev c++ developmental tool, for this output????


what is the c++ code runnable in dev c++ developmental too, for this output????


it will accept a string and creates a figure,, like in the following:





(it will be like this if the number of amount of string is an even number. and prints like a shape of a hour glass)





enter string: ccss


c c


c


s


s s

What is the c++ code runnable in dev c++ developmental tool, for this output????
do an if mod 2 on the string length to figure out if it is even or odd, if it is even generate two strings from the original by going from 0 to length/2 and length/2 to length.





For output cout from within 2 loops, one after the other, the first loop dealing with the first substring, the second loop dealing with the second substring.





The loop will simply start at the length of the substring and decrement to 0, each time printing length number of characters from the substring to the screen.





The second loop will do the same but in reverse, starting at 1 and stoping at length.





Don't understand what you ment for odd numbers but it will be similar to the above.


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

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





What's wrong?

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





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





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





int countcons (char *, char[]);


int countvows (char *, char[]);





and the definitions start as:


int countcons(char *strptr, char vowels)


int countvows(char *strptr, char vowels)





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


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


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





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


you could make them


int countcons(char *, char *);





int countcons(char *strptr, char *vowelsptr)





or you could use arrays such as:





int countcons(char *, char []);


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





You could even mix the two.


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








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


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


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


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


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


*strptr != vowels[4])


times++;


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





Am I making sense, or just confusing you more?





-------


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


-------


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

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





char *vowels="aeiouAEIUO";





int countvows(char *strptr, vowels)


{


int times = 0;





while(*strptr) {


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


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


times++;


strptr++;


} // if


} // while





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


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


}

secret garden

C++ Segmentation Fault?

Here is my code:


#include %26lt;iostream%26gt;


using namespace std;





typedef struct {


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


int num;


} SomeStruct;





void allocSpace(SomeStruct **);





int main ()


{


char * b, q, *r;


SomeStruct **arr;


allocSpace(arr);


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


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


return 0;


}





void allocSpace(SomeStruct **x)


{


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


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


{


x[i] = new SomeStruct;


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


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


}


}

C++ Segmentation Fault?
Use new not malloc,


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


Constructors and C array question in C++?

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





ex:








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








How can I make this legal?





MyType::MyType(char ar[])


:


{


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


private_member_array[i] = ar[i];


};





}











So basically,





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





MyType("data for my type");





Thanks!

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





#include %26lt;iostream%26gt;


#include "MyType.h"


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


{


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


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


return 0;


}





// header MyType.h


class MyType


{


public:


int pm_array[];


MyType(char ar[]);


};





#include "MyType.h"


MyType::MyType(char ar[])


{


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


{


pm_array[i] = ar[i];


}


}
Reply:There are different ways to do it.


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





class MyType {


private:


char *private_str;


public:


MyType();


MyType(char*);


~MyType();


}





MyType::MyType() {


private_str = NULL;


};


MyType::MyType(char* str) {


private_str = new char[strlen(str)];


strcpy(private_str,str);


};


//Helps to free memory on destruction.


MyType::~MyType() {


if (private_str) delete private_str;


};





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





class MyType {


private:


std::string private_str;


public:


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





}





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


private_str = str;


};





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





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





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





MyType::MyType (const char * text)





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


C++ strings?

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





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


contadores[texto[i]]++;





THANKS!

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





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


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





Voy a tratar de traducir estos instrucciones a espanol:


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


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





Hope that helps.





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





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


but it will jump to 2 not to 1


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


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





as my previous person answered...





thanks


Convert code from C# to VB?

Namespace yahoo


{


Class Program


{


public static int Main(string[] args)


{


TextHelper textHelper = new TextHelper();


SayHello(textHelper);


char[] output = textHelper.GetHelloArray();


foreach (char c in output)


{


System.Console.WriteLine(c);


}


string outputString = textHelper.HelloWorldProperty;


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


{


System.Console.WriteLine(outputString[...


}


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


System.Console.WriteLine();


int input;


do


{


input = System.Console.Read();


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


ExerciseSwitch(1);


ExerciseSwitch(2);


ExerciseSwitch(3);


ExerciseSwitch(Square(2));


return 0;


}


private static void SayHello(TextHelper textHelper)


{


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


}


private static long Square(int x)


{


return x * x;


}


private static void ExerciseSwitch(long y)


{


switch (y)


{


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


goto case 2;


case 2:


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

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





http://converter.telerik.com/





There are a few other sites as well.





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





Good Luck

pear

C++ Strings?

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


cout%26lt;%26lt;endl;


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


getline(cin,phrase_input);





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


{


beg = phrase_new.substr(0,random_one);


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


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





shuffled_phrased+= endphr;


shuffled_phrased+= beg;


shuffled_phrased+= mid;





}


cout%26lt;%26lt;shuffled_phrased;

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





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





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





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


If not, I suggest you learn.





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





Learn to use breakpoints and the call stack.


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

This is my struct:





struct PlayerRecord


{





string playerID;


int playerNum;


int playerPoints;





};





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


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

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





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


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


C++ Strings?

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





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


{





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





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








return;


}





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

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


C++ Strings?

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





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





char A;





using namespace std;





int main (){


system("net view") = A


string str1( A , 11, 4 );


}


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

C++ Strings?
int main (){


A = system("net view")


string str1( A , 11, 4 );


}





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

nobile

Snapped a cello string!?

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

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





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





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





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





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


I need help with pointers in C++?

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


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


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


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


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


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


*/


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


using namespace std;





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





int main(){


string sentence;


int *pFront, *pRear;


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


cin %26gt;%26gt; sentence;


swap_char(pFront, pRear);


return 0;


}


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


while(pRear %26gt; pFront)


{


string sentence;


char temp;


%26amp;temp =

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





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





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





void swap_char(char * const s);





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





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


swap_char(sentence.c_str());





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





So you need something like this:





getline(cin,sentence);


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


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


swap_char(line);





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





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





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


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.


How to do it using arrays and or strings C++?

using Arrays and/or Strings





Enter 8 numbers and drop the lowest and highest and then adding the rest and output the score with two decimal places

How to do it using arrays and or strings C++?
The best place would be to start with the pseudo code version. Remember, an array is just a list of objects strung together (technically, a string is the same as a character array)


For simplicity, this assumes that you will not have a highest and lowest that appear multiple times.





try something like this


read in 8 numbers cycling through each one to fill up the array.


have 2 variables to store the current max and current min


begin processing through the array. the first item is both the highest and lowest number at this point.





move to the next number, if it's higher then the stored high number, change the stored high number to this one. (same thing on the other side if it's lower)





when you get to the end of the list you'll know which one is highest and which is lowest.








create a collector variable.


process all entries except for these 2 items adding each one to the total





hope this helps.
Reply:wow c++ that was freshman yr umm try puttin in order then comand to drop max and Min i forget that code sorry it dont help

flower girl dresses

C++ code to replace words in a document, keep getting run error?

string replace


string aword;


char c;





string in_file_name = "Slim Shady.txt";





ifstream fin;





fin.open(in_file_name.c_str());





if(!fin)


{


cout %26lt;%26lt; endl


%26lt;%26lt; "could not open " %26lt;%26lt; in_file_name %26lt;%26lt; flush;





cin.get();





return -1; //Can't carry on if the file is not open


}





string out_name = "";





out_name = out_name + "clean_" + in_file_name;








ofstream fout;





fout.open(out_name.c_str());





if(!fout)


{


cout %26lt;%26lt; endl


%26lt;%26lt; "could not open " %26lt;%26lt; out_name %26lt;%26lt; flush;





cin.get();





return -1; //Can't carry on if the file is not open


}








//Ask user for foul_word


if (!fout)


{





cout%26lt;%26lt; " input foul_word"%26lt;%26lt;endl;





cin%26gt;%26gt; "foul_word"%26gt;%26gt;endl;





cin.get();





return -1;











//make expletive using foul_word





//change foul_word to upper case








string expletive= makeexpletive(foulword);





foulword toupper(foulword);








fin %26gt;%26gt; aword;





while(!fin.fail())


{





string temp= toupper aword


int where = temp.find (0,foulword);





if(where!=-1)


{


}


aword.replace





string temp= replace( foulword, string temp(), s2 ); cout %26lt;%26lt; s %26lt;%26lt; endl


//create temp string that is tuupper version of aword





//if foul_word is in temp then replace foul_word with expletive in aword





aword.replace( where,foulword.length(),expletive);








fout %26lt;%26lt; aword;





fin.get( c );





while(isspace(c))


{


c = toupper(c);





fout %26lt;%26lt; c;





//in case the end of file is a space


if(fin.fail())


{


break;


}





fin.get(c);


}





aword = "";





aword = aword + c;





string next_word;





fin %26gt;%26gt; next_word;





aword = aword + next_word;








}


//cin.get();





fin.close();


fout.close();





return 0;





}











string toupper(string s)


{


string temp = "";


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


{


char c = toupper(s[i]);


temp = temp + c;


}


return s;


}





string makeexpletive(string s)


{





char face;


string temp ="";





srand(time(0));








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


{





face = rand() % 5 + 1;





switch(face)


{


case 1 : temp = temp + '$'; break;


case 2 : temp = temp + '%26amp;'; break;


case 3 : temp = temp + '?'; break;


case 4 : temp = temp + '*'; break;


case 5 : temp = temp + '@'; break;





}


}





return temp;


}

C++ code to replace words in a document, keep getting run error?
Telling us what Run Error you're getting might help. Besides the fact that you don't even say what compiler you're using, few people here want to take the time to cut-and-paste all your code into our compiler, then work through getting it to compile and start running to find out what it MIGHT be.





Sorry that's not directly helpful, but it's good advice.
Reply:hey dude, u missing some semicolons maybe. at least i spot one.





string replace //u forgot to put a semi colon here





and did u write


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;fstream%26gt;


#include %26lt;string%26gt;


etc etc.??
Reply:(what%26gt; the}


Run...hell=you


switch....


talking@@[dd}


((0))


about.


C++ (palindrome strings?)?

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


else


return false

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


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





Other things to consider:


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





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


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


Checking user input from c++ style strings?

I have to make a program where the user inputs an integer, and then I have to do some stuff to the integer, and then output it. Easy, but I want to make it so that the program checks if the user entered an integer or not; if they enter something other than an int, I don't want the program to crash.





I want to let the user enter something, and it will be stored in a c++ style string (from #include %26lt;string%26gt;), and then check the string to see if it is an integer. That way is safe, but I have no clue how to check a c++ style string.

Checking user input from c++ style strings?
The way I would design it is to have the input as a string, then set up a loop from 0 to strlen(input) - 1 and do an "isdigit" function on it. (if you're allowing negative numbers, then do special processing on the 0th byte of the string to account for this possibility).





Once isdigit is false, it's safe to leave the loop, throw the input away, and prompt for another try.





If the loop completes with isdigit always being true, then "atoi" it into a numberic varaible, then do your processing.
Reply:I think there might be an isInt function or something like that in the string library. I'd say go to cplusplus.com, search type checking, they'll have something good for you.

flower garden

Problem on C program(strings)...please try to solve.?

write a C function void str_copy_drop(const char * string1, char * string2, char ch)


which copies the string string1 to string2 but with all occurrences of the character


passed as parameter ch omitted.








HERE IS WHAT I HAVE TRIED: its funny but can you check it and write me a correct program..





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


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


void str_copy_drop(const char *string1, char *string2, char ch);








void str_copy_drop(const char *string1, char *string2, char ch)


{


char *s1[20],*s2[20];








FILE *input;


input =fopen("string.txt","r");





fscanf(input,"%s",%26amp;s1);





s2= strcpy(s2,s1);


printf("\ncopied string is %s\n",s2);


}








above programs is wrong...i need solution for question described above..





Many thanks!!

Problem on C program(strings)...please try to solve.?
Use this function instead of yours. It would work fine.





void copy(char *s1,char *s2,char ch)


{


while(*s1!='\0')


{


if(*s1!=ch)


{


*s2=*s1;


s2++;


}


s1++;


}


*s2='\0';


}








U can ask more such..








OM NAMAH SHIVAY
Reply:/*


copy all characters from string1 into string2 except ch





method:


walks through each character in string1 using a pointer to


the characters, stopping at the C end-of-string char '\0', and


steps the pointer by the sizeof(char)





appends an end-of-string char to the output string2 after all valid characters have been copied.





NOTE BENE: output buffer (string2) must be sufficient to hold all characters of input buffer (string1). No checking is done to ensure this here.


*/


void str_copy_drop(const char *string1, char *string2, char ch) {





if (( 0 != string1 ) %26amp;%26amp; ( 0 != string2)) {


char* p1 = (char*)string1;


char* p2 = string2;





while ( (*p1) != '\0' ) {


if ( (*p1) != ch ) {


(*p2) = (*p1);


p2 += sizeof(char);


}


p1 += sizeof(char);


}


(*p2) = '\0';


}


}





You'll have to format the indentation yourself, as yA doesn't allow tabs.
Reply:you would have to go through the string, character by character and compare it with the parameter ch. if it matches then dont copy it to the new string. you need to know the length of the string so you know how many characters to compare.





pseudocode:


set 2 counters to 0


get length of string


loop "length of string" times


if string1[couter1] = !ch


copy string1[counter1] to string2[counter2]


increment counter2


loop until at end of string1





just a note (going by your function declaration), the file should be opened outside of the routine and read. then pass the pointer to the string. you dont need the "char s1, s2 pointers since you are passing the string pointers to the function (which you are not using by the way).


How do you compare strings in c++?

I have no Idea how to make sense of compraing strings in c++





for example, a statement such as -(someString1 %26gt; someString2)





how does this make any sense?





how can letters be greater than or less than each other?





please help.

How do you compare strings in c++?
1. "how can letters be greater than or less than each other?"





a: Each character has a numeric value. 'C' has a numerically greater value than 'B'. Thus, this is a valid expression, and prints "1":


cout %26lt;%26lt; ('C' - 'B') %26lt;%26lt; endl ;





...and this (should) print "67"


cout %26lt;%26lt; 'C' %26lt;%26lt; endl;





2. "for example, a statement such as -(someString1 %26gt; someString2) how does this make any sense"





a: since a string is a sequence of characters, and each character has a numeric value, then a string has a numeric value. And thus one string may have a greater numeric value than another. This fact is exploited in string sorting algorithms. It's how Windows Explorer, for example, sorts your directory entries and makes them all neat for you.





a statement such as


if(someString1 %26gt; someString2)


....





won't do what you expect [ie: compare the strings] unless you overload the "%26gt;" operator. Generally, we'd overload it with the strcmp() function in a class implementation like so:





boolean string::operator %26gt; (const string %26amp;str)


{


return strcmp(data, str.data) %26gt; 0;


}
Reply:No, actually in C++ you can use the == operator to directly compare because it's been operator overloaded. It does *not* compare the memory addresses as what would happen in C. I could be wrong, but I'm sure C++ also overloads the %26lt; and %26gt; operators that conform to lexicographical order (which is comparing each letter until they differ or one ends and tests the value of the characters to determine whether a string is larger than the other).
Reply:well the best I would say is would be to say str1 == str2 for equality in strings, but as for saying is one greater then another I don't think there is a way simply because as far as I can think of it would have no real use. now you can compare lengths( in java its (name).length() ), but being a heavy user of Java I forget what the command is.
Reply:In C++ strings are pointers to characters, so statements like "string1 == string2" or "string1 %26gt; string2" will simply compare the *pointer* values, not the actual strings that they point to.





To compare strings in C++ use strcmp(). If you check the documentation you'll find there are several variants of this function e.g. for case insensitive compares, comparing only a set number of characters etc.
Reply:First realize that a string is stored internally as a series of numeric values (ASCII, ANSI,UNICODE, etc) and that text is merely an output-time representation. So in a binary sense it's a completely rational operation.





But typically, when strings are compared as one being greater or less than another, the op infers alphabetic order, 'and' %26lt; 'army'; 'dog' %26gt; 'cat', etc. One word is greater than another because it comes after the other in a dictionary.





If the comparison is case-insensitive, then 'Dog' %26gt; 'cat' is still true, but if it is case-sensitive, then 'aardvark' %26gt; 'Zoophilia' is true, because the ASCII values of all upper-case letters are lower than that of lower-case 'a'..


How do you concatenate strings in C#?

I need to concatenate three strings called Month, Balance, and Interest. What's the correct syntax in C#?

How do you concatenate strings in C#?
the simplest answer to this would be simply doing the following


String trial ;


trial =+ "what ever I want to add here";


trial =+ "here i add some more to the string";





Hope this helps
Reply:using System.Text;


...


StringBuilder sbStatement = new StringBuilder();


sbStatement.Append(Month);


sbStatement.Append(" ");


sbStatement.Append(Balance);


...


string strStatement = sbStatement.ToString();


... Report It

Reply:Hi, its me again. There is a Concat function of the String class or you can use the overloaded + operator.





String.Concat(Month, Balance.ToString());





strVariable = Month + Balance.ToString() + Interest.ToString();





Hope this is what you were looking for.


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

Firstly its cin%26gt;%26gt;


u'll also need the command getline()


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

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





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

edible flowers

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

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





Assuming,


string searchString = "abcbdefb";


char charToFind = 'b';





Regular Expressions:


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





IndexOf:


int numberOfChars = 0;


int lastIndex = 0;


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


{


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


if (lastIndex == -1) break;


numberOfChars++;


}

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