Friday, July 31, 2009

How do u declare a string to be null / empty in C ?

say I got a variable "char[] something = "Hello World" "


Now I want something to be empty, null. How do I do this ?

How do u declare a string to be null / empty in C ?
something.empty();
Reply:char[] something="" or char[] something=NULL. or char[] something=0.
Reply:Actually, if you are using 'C', and you just want the string to be 'empty' (i.e. still be accessable by address, but contain no characters, then you need to set the first character to '\0' (ASCII value 0) since all C strings end with a 'null' character.





Note, this is different from "NULL", which is used to initialize pointers. Now, assuming this is valid ANSI C and you used:





char something[] = "Hello World";





Then you could basically empty the string by using:





something[0] = '\0';





However, be very careful. Because you did not specify a size of the array, you will only be able to copy no more than 12 'char' values into the string (the length of "Hello World" plus its 'null' character). If you were to empty the string, then use strcpy() or other direct means to fill this string array, you would cause stack or heap corruption if you overstep that twelve char boundary.





You can do something like this:





char something[1024] = { "Hello World" };





This will ensure that you have up to 1024 characters of space (minus one for the ending null character) that you can use later to fill up with larger strings.
Reply:string is an array ends with the character \0


How do you convert a string sentence to an int in C#?

int val = Convert.ToInt32("123");


When using c++ i need an example code of a broken string?

like what it is for example 1,2,3,4,5ive is what i have seen in examples but i dont under stand how a string can brake and y it brakes and if possible an any 1 explain y using globle varibles is so bad

When using c++ i need an example code of a broken string?
You need to slow down.





Learn English first (no offense - or ask this question in a forum that is in your native language), then take basic class on C programming before going into C++.


Simple program of stack using string for push pop functions using c?

Yes, it's simple once you learn how to do it. How are you coming along?

Simple program of stack using string for push pop functions using c?
Simple answer.

flower garden

How would i split a string into a char array in c++ ?

so i have asked the used to enter a word. Let's say they type in "baby"..how would I split it so that I can get an array with array1[b], array1[a], array2[b], array3[y]..thanx in advance

How would i split a string into a char array in c++ ?
string str = "baby";


string arr [str.length];


for(int i=0; i %26lt; str.lenght; i++)


{


arr[i] = str[i];


}
Reply:http://en.allexperts.com/q/C-1040/Explod...


C++ help with strings?

What are the major differences between (C strings) and the (string) class?

C++ help with strings?
The difference between living in a universe with a sun and one with eternal darkness.





string class is


easily expanable


easily copyable


has built in equality operators


has a multitude of insert, replace, etc., methods;


has iterators and revere iterators


can be passed to many stardard library algorithms





just off the top of my head.


In C++, how do you print quotation marks with an string in the middle?

For example:


I want to print:


" Blah blah blah "





Blah blah blah is a string.





it won't work like this:


cout %26lt;%26lt; "Movie name: " %26lt;%26lt; setw (30) %26lt;%26lt; "\" %26lt;%26lt; movieName \"" %26lt;%26lt; endl;

In C++, how do you print quotation marks with an string in the middle?
It looks like your line should be like this:





cout %26lt;%26lt; "Movie name: " %26lt;%26lt; setw (30) %26lt;%26lt; "\"" %26lt;%26lt; movieName %26lt;%26lt; "\"" %26lt;%26lt; endl;





You need to use "\"" when you want a string that just contains a double-quote character
Reply:I thought that \" worked.
Reply:Your code not work becuse you must write:


cout %26lt;%26lt; "Movie name:" %26lt;%26lt; setw(30) %26lt;%26lt; "\"" %26lt;%26lt;moveName "\"" %26lt;%26lt;endl;


an other example:


to output : Blah "BLAH" blah


you must write:


cout%26lt;%26lt;"Blah \"BLAH\" blah";


In C++, how do you convert an integer into a string or character?

For example, I want to be able to read in the int 65 and for it to return the string or char "a". I want it to do this for every number entered. Is there a member function that does this?

In C++, how do you convert an integer into a string or character?
Char to Int





char word = 'a';


cout %26lt;%26lt; (int)a;


Displays: 65





Int to Char





int Number = 65;


cout %26lt;%26lt; (char)Number;


DIsplays: a
Reply:try


itoa();





function ,its a C function though will work fine,


im bit sure...
Reply:Msdn is a great source for code and examples. However like in most other languages you would use the TryParse method. For example in C# it would be:





int one;


char[30] two;





Tryparse.Int32(one, two);
Reply:the first answer: casting the int to char using (char) a is the correct answer.





itoa() will return the string "65".





There is nothing in C++ like TryParse. Dear answerer, if you have learnt something in some language or it's associated library, try and keep it limited to that language and not assume that it is a very common thing available in all programming languages.





Actually the commonality between programming languages are more of exceptions than rules.
Reply:try (char)


like


int a = 65;


char b = (char)a ;

edible flowers

How to print a string without using print statement in c?

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





int


main()


{


int i = 12;


char tmp[32];


snprintf(tmp, sizeof tmp, "%d", i);


puts(tmp);


return 0;


}








OR








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


%26gt;


%26gt; void putint(int x);


%26gt;


%26gt; int main(void)


%26gt; {


%26gt; puts("[output]");


%26gt; putint(13725);


%26gt; putchar('\n');


%26gt; putint(5500);


%26gt; putchar('\n');


%26gt; return 0;


%26gt; }


%26gt;


%26gt; void putint(int x)


%26gt; {


%26gt; if (x) {


%26gt; putint(x / 10);


%26gt; putchar('0' + x % 10);


%26gt; }


%26gt; }


%26gt;


%26gt; [output]


%26gt; 13725


%26gt; 5500





OR








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


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


...


char buff[1+(CHAR_BIT*sizeof(int)+2)/3+1];


sprintf (buff, "%d", the_integer);


puts (buff);

How to print a string without using print statement in c?
fputs(const char* string, FILE* stream).





since stdout is a file just do:





fputs("string to print",stdout);


Converting a string, to a vector of ints, to binary, to hexadecimal. (C++)?

I need to create a program that will accept a string inserted by the user, which represents an unsigned int. I need to convert this string to a vector of ints, and then convert the number to binary and hexadecimal. This is what I have so far:





#include %26lt;iostream%26gt;


#include %26lt;vector%26gt;


#include %26lt;string%26gt;


#include %26lt;cstdlib%26gt;





using namespace std;


int main(void)


{


cout%26lt;%26lt;"Input a decimal:"%26lt;%26lt;endl;


string s;


cin%26gt;%26gt;s;





vector%26lt;int%26gt;n(s.length());





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


{


n[i] = s[i] - 48;


}





return 0;


}

Converting a string, to a vector of ints, to binary, to hexadecimal. (C++)?
Your code assumes that the string entered only contains ASCII digits. You should explicitly check for this:





if ( isdigit( s[i] ) ) {





Next, you can also use a standard function to convert a string to an integer for you:





n[i] = atoi( s[i] );





(if you ever want to convert the entire string to a single integer, you could use strtol() ).





Give these a whirl and see where you end up. Go to the URL below and type "atoi" in the search field.


C++ strings?

i'm trying to convert a string (baseStr) to an array (baseArry):





string Convert(string baseStr)


{


int baseLength = (size_t)baseStr.length();


char* baseArry = NULL;


baseArry = new char[baseLength];


strcpy_s(baseArry, baseLength, baseStr.c_str);


}





It compiles okay, but when I run it, it says that the buffer is too small. Did I allocate my memory incorrectly?

C++ strings?
change baseLength line to this


size_t baseLength = (size_t) (baseStr.length() + 1);





And Convert function should be


char *Convert(string baseStr)


and return baseArry as the result;


I am having trouble soloing with two string scales,(mexican music), how does c scale go on the bottom strings?

using the e and b strings together for one note is what i mean

I am having trouble soloing with two string scales,(mexican music), how does c scale go on the bottom strings?
ask in music instrument section or google it

covent garden

In C++ what is the easiest way to convert a string (std::string) to type int?

Lets say I have a String number


number="100"


whats the easiest way to conver this string into an int type

In C++ what is the easiest way to convert a string (std::string) to type int?
Use the standard library functions atoi (ascii to int), atof (float), or atol (long):





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





int x = atoi("100");


float y = atof("100.1");


long z = atol("1000000");
Reply:Use streams:


string number= "100";


int x;


istringstream i(number);


if (i %26gt;%26gt; x)


cout%26lt;%26lt;x;


else


cout%26lt;%26lt;"Input not a number";





You have to include sstream for using this code. Now if you want to convert the number to float, just declare x as float and let the operator overloading do the rest.





I have provided you the code, now search net what does istringstream do and what magic can you perform with streams.
Reply:...


string s("999");


int n = atoi(s.c_str());
Reply:define it in a variable
Reply:I believe you could also simply "cast" the variable.


Here's the syntax: static_cast%26lt;type%26gt; (object)





static_cast%26lt;int%26gt;(x);





cout %26lt;%26lt; "x as integer" %26lt;%26lt; x %26lt;%26lt; endl;





I'm also pretty sure that there's no special include statements.





Hope that helps!





Rob


I am having trouble soloing with two string scales,(mexican music), how does c scale go on the bottom strings?

using the e and b strings together for one note is what i mean

I am having trouble soloing with two string scales,(mexican music), how does c scale go on the bottom strings?
tryasking in the music/ instrument section

email cards

Which string is better for panties: g, c, or v?

IF you are a boy, G-string are very sexy and nice to wear.


You have also bikini string panties.


Just go to frederick of hollywood.com and you will find out a lot for boys and girls.

Which string is better for panties: g, c, or v?
g


Ca i get any saample code in C language for encryption and decryption of a string?

i wanna hav a sample code that gets a string as its input and uses some random numbers as the key values and encrypts the string. the same random numbers should be used to decrypt the string...

Ca i get any saample code in C language for encryption and decryption of a string?
take a look at this page:








simple encryption using table :


http://www.planet-source-code.com/vb/scr...
Reply:www.c++.com
Reply:www.programmersheaven.com


How to read a string from a text file in asp.net using c#?

Actually, I put a connection string in a text file and I need to read the connection string from it. Below, is my text code, but still can't made it.





string FILENAME = System.Web.HttpContext.Current.Server.Ma...





StreamReader objStreamReader;


objStreamReader = File.OpenText(FILENAME);


m_strConnString = objStreamReader.ReadToEnd();


objStreamReader.Close();





Can anybody help me? Thanks.

How to read a string from a text file in asp.net using c#?
you can do this much more effectively w/ configuration files. Add a Web.Config file to your project and add a connectionstring element. then read the value out via the ConfigurationManager static class. This is by far the preferred solution as .config files are automatically blocked by IIS and cannot be downloaded by bots, malicious users, etc.





Example provided is in VB.Net, but you should be able to get the gist =)
Reply:Connection strings should be placed in configuration files instead of text files.





Thats exactly what configuration files are for. Application wide (or machine wide) configurations.





Hope this helps.


I want a program whith c++ (it should get a string a=[12 3;4 5.5] and put the numbers in a matrix )?

it should understand size of matrix and put numbers in it,s arrey

I want a program whith c++ (it should get a string a=[12 3;4 5.5] and put the numbers in a matrix )?
I didn't find out what exactly you want but if you mean that you must enter a string like [12,13,25.5,123,12] and the program puts them into a array it's very easy. else it's not the case you can mail me and I'll tell you the soloution.


NOTE: I didn't test the program cuz i'm right now at cofenet and it might not work correctly and depending on your compiler you may change some of lines. I recommend Microsoft Visual Studion 6 or Borland C++ for you








//this programs wrote in a old style and


//works with many compilers


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


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


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


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





void main()


{


double *array;


char string[255], *temp,*ptr, *tptr, number[10]; //or more


cout %26lt;%26lt; "Enter your desigered string: " %26lt;%26lt;endl;


cin.getline(string, 255);


temp = new char [strlen(string) + 1];


strcpy(temp , string);


int size;


ptr = strtok(temp, ',');


for (size = 1; ptr != NULL; size++)


ptr = strtok(NULL, ',');


array = new double [++size];


int i = 0;


ptr = strtok(string, ',');


strncpy(number, string + 1, ptr - string - 1); //ignore [


number[ptr - string] = '\0';


array [i] = atof(number);


tptr = ptr;


ptr = strtok(NULL, ',');


while (ptr != NULL)


{


strncpy(number, tptr + 1, ptr - tptr - 1);


number[ptr - tptr] = '\0';


array [++i] = atof(number);


tptr = ptr;


ptr = strtok(NULL, ',');


}


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


cout %26lt;%26lt; "The array [" %26lt;%26lt; j %26lt;%26lt; "] = " %26lt;%26lt; array[j] %26lt;%26lt; endl;


}

cheap flowers

What is a literal in C?Is it a)Stringb)String Constantc)Character d)Alphabet?

A literal is any piece of program whose value is apparant (obvious) from just reading it.


Such as an int, char, string, double literals:


soo an int literal would be 7


a char would be C


a double would be 7.6


a string would be "HIYA!"


Hope this helps! :)

What is a literal in C?Is it a)Stringb)String Constantc)Character d)Alphabet?
The answer is........ character ( i think)


Can you give me a c program of palindrome using string functions but without str reverse?

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





int isPalindromo( char *s ){


char *s2 = s + strlen( s ) - 1;


if( !*s )


return 1;


while( *s++ == *s2-- %26amp;%26amp; *s );


return !*s %26amp;%26amp; *( --s ) == *( ++s2 );


}





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


char s[255];





printf( "Texto:" );


gets( s );


printf( "%s \n", isPalindromo( s ) ? "YES" : "NO" );





system( "pause" );





return 0;


}


C++: Cocatenating an int to the end of a string?

I need to know how to concatenate an int to a string, the simplist way possible.





Here is a snippet of my code (only elementCoefficients[index] is an int) :





string buildChemicalFormula(int elementCoefficients[])


{


string formula = "";


int index;


for(index = 0; index %26lt; numberOfElements; index++)


formula = formula + elements[index].chemicalSymbol + elementCoefficients[index];





size_t location;


size_t index1;


for(index1 = 0; index1 %26lt; formula.length(); index1++)


{


location = formula.find("0", 0);


if(location !=string::npos)


{


formula.erase(location-1, 2);


index1 = index1 - 2;


}


}





return formula;


}





When I try to create the new formula, the compiler outputs, " error C2676: binary '+' : 'std::basic_string%26lt;_Elem,_Traits,_Ax%26gt;' does not define this operator or a conversion to a type acceptable to the predefined operator".





I tried casting the ints to chars but didn't work.

C++: Cocatenating an int to the end of a string?
You should be able to use the itoa() function (integer to alpha). Here's more information. http://www.cplusplus.com/reference/clibr...
Reply:Do all your additions as int. When you are ready to print the string, use string + int and it will do automatic string conversion.


Write a program in c language to reverse a string using pointers?

These other guys are correct - you should not just throw out homework questions without making an attempt to learn yourself. In the case we are wrong, and you are stuck altogether, here is a dirt-simple program that will do what you need. I hope you learn something from this.





-----


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





/* here is your "test" string */


/* you will probably want to read you array


* from stdin or something, but this hard-coded


* version will serve to illustrate


*/


char original_string[64] = {"Testing 1 2 3"};


char reversed_string[64];





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


{


int i;


int count;


char* output_ptr;








count = strlen(original_string);





output_ptr = reversed_string + strlen(original_string) - 1;





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


{


*(output_ptr - i) = *(original_string + i);


}





/* verify results */


printf("Original string: %s\n",original_string);


printf("Reversed string: %s\n",reversed_string);





}

Write a program in c language to reverse a string using pointers?
Why are you asking all these questions?


Do your own homework, for crying out loud.





If you need help with something, then post your code. Otherwise, it's just rude of you to ask other people to waste their time on you.
Reply:Show us what you have so far instead of putting no effort into it at all.

baseball cards

A function in C that reads in a String of text and counts the number of characters including space in the text

The text max is 250

A function in C that reads in a String of text and counts the number of characters including space in the text
strlen(const char *s)
Reply:#include %26lt;string.h%26gt;


char str[250] = "Hellooo this is a test";


int len = strlen(str); //Len = 22


1.write a c program to accept a string and convert it to upper case without using to upper(),without using poi

here some code...





char str[20]="aBcdeG_er23d*d";


int index=0;





while(str[index]!='\0')


{





if ((str[index]%26gt;='a') %26amp;%26amp; (str[index]%26lt;='z'))


{


str[index]=str[index]-32


}





index++;


}





cout%26gt;%26gt;str%26gt;%26gt;endl;








thank you reading my poor help...

1.write a c program to accept a string and convert it to upper case without using to upper(),without using poi
Huge hint: www.asciitable.com
Reply:I don't know how to write in C, but I can trry to give you some basic ways of convertng to uppercase:


Im not sure what poi means but i think you could compare each letter in the string, using a loop, to an array containing the alphabet and create another identical string with uppercase letters, if that made any sence...





There is a way to compare each of the letters in the string variable in ascii format and i think you can then use a formula to convert that letter to uppercase


for example, in acsii, the decimal equivilant to "a" is "97" and "A" is "65", "b" is "98" and "B" is 66 and so on, so you can maybe make something like this (remember, I cant program is c..): if ((Integer)firstLetter.inASCII()%26gt;=97%26amp;%26amp;(In... then (Integer)firstLetter.inASCII()-22=newFir... I dont know if this made any sence to you, if I new more about C then I could be more specific, maybe you can go somewhre with this


Please write a c function to reverse a string , any one help me ?

I'll assume that you really want to learn from the assignment you are given, rather than just have someone give the answer to you outright.





To reverse a string, you need to first exchange the first and last characters in the string. So, figure out the index of the last character in the string, and this will be easy. You'll need to calculate the length of the string to do this.





With this done, you can continue the process by exchanging the second and next-to-last character of the string. In fact, you can write a loop to perform the appropriate exchanges until you are finished.





Figuring out the terminating condition of the loop requires a little thought, and you should consider the two cases of strings of odd and even length. Drawing a picture may help here.





Ultimately, this problem can be solved by breaking it into smaller problems, each of which can be solved with a little thought. This is what your instructor hopes you will do. Developing these problem solving skills is what will make you a valuable employee.

Please write a c function to reverse a string , any one help me ?
#include %26lt;string.h%26gt;


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


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











int main() {





char s[1000];


int i;


int len=0;





while (1) {





printf("\n\n\tEnter a string : ");


gets(s);





printf("\n");





for(i=0;s[i];i++) {


printf("%c",s[i]);


}


len=strlen(s);


printf("\n\n");


for(i=len-1; s[i], i%26gt;=0; i--)


printf("%c",s[i]);


}


return 0;


}
Reply:Hi, i dont remember exactly , but i can give u the steps, u have to try urself:


if the number is x,


then first take the remainder of this number dividing by 10, which will give you te last diggit of this number, get it printed,


then find the integer value of it while dividing by 10.


then repeat the above steps on this number.





example:


if number x = 123,


dividing by 10, will give the remainder as 3., so save ths number.


now dividing by 10 and finding the ointeger value, it will be 12,


again repeating the above step,


divide this number by 10 for finding remainder, which will be 2,again save ths number


and diving by 10 for finding integer value, u will get 1, which is the last digit, so save this also, now if u print in sequence, the saved numbers, u will get:


321,which is the reverse of the number x.
Reply:Do your homework! Hint... stack.


C++ Counting the number of words in a string?

How would you go about counting the number of words in a string and the number of occurences of each individual letter? Is there an easy way to do the counting or will I need to create like 26 different loops to do the counting?

C++ Counting the number of words in a string?
***note: the following code may not be completely accurate. it is meant to show a way to get the solution, but there may be bugs.





basically:





1) keep track of a word count using the # of spaces there are, not counting the 1st or last position.





2) keep track of a letter count, with the index of the array being the letter, and the contents being the # of occurances of that letter.





---





#include %26lt;stdio.h%26gt; /* standard in/output include file */


#include %26lt;string.h%26gt; /* include file for string functions */








#define MAXlength 50 /* max. length of test_string */








main()


{


char i, /* used as a counter */


ch, /* a temporary character */


strsz; /* the length of the string */





char test_string[MAXlength]; /* the string being dealt with */


char alpha_count[26]; /* the letter count (of 'aA'-'zZ') */


char word_count=0; /* the word count */





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


alpha_count[i]=0; /* set counts of letters to 0 */





/* --- insert code here for inputting the string from the user */





strsz=strlen(test_string); /*sets strsz to the lngth of the string */





for(i=0;i%26lt;strsz;i++) /* go through each character of the string */


{


if(test_string[i]==' ') /*if it's a space, and the space */


if((i%26gt;0)%26amp;%26amp;(i%26lt;(strsz-1)) /* is not at the beginning or end of */


word_count++; /* the string, increase the wordct. */





ch=toupper(test_string[i]); /* ch = uppercase of the letter */





if((ch%26gt;='A')%26amp;%26amp;(ch%26lt;='Z')) /* if it's a letter between 'A'-'Z' */


alpha_count[ch-'A']++; /* keep track of that letter */


}





printf("In '%s':\n,test_string);


printf("There are %d words.\n",word_count);


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


if(alpha_count[i]%26gt;0) /* don't show counts for letters that */


/* aren't there */


printf("There are %d '%c's\n",alpha_count[i],'a'+i);


}

artificial flowers

How can I grab user input using cin in C++ then take that and create a string with that name?

I am making a program for storing contact data for an assignment and need to know how I can make the string's name the same thing the user input. This is not for school :).

How can I grab user input using cin in C++ then take that and create a string with that name?
As far as I know there is no way of doing that directly, however, here is an idea of accomplishing a similar thing:





C++ has a data type (a thing to store data -- like an int, double, string, etc.) called a "hash map" (some people call it a "hash table", too, both are correct). It stores things in pairs of "key"s and "value"s. Some example keys and values for your program might be:





KEY (name) / VALUE (age):


Bob / 16


Sally / 17


Bill / 40





To create a hash table, first include the proper library for it (#include %26lt;map%26gt; where you include everything else such as iostream or string, etc.), and then somewhere in your program, declare it in the following way:





map%26lt;string, int%26gt; my_hash_map;





This creates a new map variable named "my_hash_map" which has strings for keys and ints for values (as in our example with names and ages).





To add a person and their age to the map, do the following:





my_hash_map["Bob"] = 16;


my_hash_map["Sally"] = 17;


my_hash_map["Bill"] = 40;





When you want to look up someone's age, you can do the following (prints "Bob's age is 16; Sally's age is 17; Bill's age is 40"):





cout %26lt;%26lt; "Bob's age is " %26lt;%26lt; my_hash_map["Bob"] %26lt;%26lt; "; Sally's age is " %26lt;%26lt; my_hash_map["Sally"] %26lt;%26lt; "; Bill's age is " %26lt;%26lt; my_hash_map["Bill"] %26lt;%26lt; endl;





You can find more information on hash maps including how to delete items at it's C++ Reference page: http://www.cplusplus.com/reference/stl/m... .


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!


Write a C++ program that reads a string and print the number of digits, number of space, number of upper case?

thx 4 helping :)

Write a C++ program that reads a string and print the number of digits, number of space, number of upper case?
The previous reply didn't answer the exact question you asked, but did show you what to do. My code below does what you're asking for. The character counting is pretty basic stuff, so I thought I'd toss in some C++ tricks to make it interesting, and help you learn something.





One nice thing about setting up the code this way is that if your want to count a different set of characters, you don't have to do anything to the code in main( ).





#include %26lt;string%26gt;


#include %26lt;iostream%26gt;


#include %26lt;cctype%26gt;





using namespace std;





struct Counts {


int digit;


int space;


int upper;


Counts() {


digit = space = upper = 0;


}


void count(const string%26amp; s) {


for (string::const_iterator i = s.begin(); i != s.end(); i++) {


if (isdigit(*i)) ++digit;


else if (isspace(*i)) ++space;


else if (isupper(*i)) ++upper;


}


}


};





ostream%26amp; operator%26lt;%26lt;(ostream%26amp; os, const Counts%26amp; c) {


os %26lt;%26lt; ". digit = " %26lt;%26lt; c.digit %26lt;%26lt; endl;


os %26lt;%26lt; ". space = " %26lt;%26lt; c.space %26lt;%26lt; endl;


os %26lt;%26lt; ". upper = " %26lt;%26lt; c.upper %26lt;%26lt; endl;


return os;


}





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


string str;


struct Counts cnt;





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


getline(cin,str);


cnt.count(str);


cout %26lt;%26lt; "Counts:" %26lt;%26lt; endl %26lt;%26lt; cnt;


return 0;


}
Reply:#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;cctype%26gt;


using namespace std;


int main()


{


string text;


cout %26lt;%26lt; "Please enter the text and terminate with a period(.) and press enter:\n";


getline( cin, text, '.');


int t,


numberOfSpace = 0,


numberOfWords = 0;





bool fSpace = true;


for( t = 0; t %26lt; text.length(); ++t)


{


if( isspace( text[t]) )


{


++numberOfSpace;


fSpace = true;


}


else if( fSpace)


{


++numberOfWords;


fSpace = false;


}


}


cout %26lt;%26lt; "\nYour text contains: "


%26lt;%26lt; "\ncharacters: " %26lt;%26lt; text.length()


%26lt;%26lt; "\nwords: " %26lt;%26lt; numberOfWords


%26lt;%26lt; "\nspaces: " %26lt;%26lt; numberOfSpace


%26lt;%26lt; endl;





system("PAUSE");


return EXIT_SUCCESS;


}


Write a C program to convert prefix string to postfix?

it wud be helpful if u can convert it to C...








/*Convert prefix to postfix expression.








*/


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


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





//Prototype Declarations


void preToPostFix (char *preFixIn, char *exprOut);


int findExprLen (char *exprIn);





int main (void)


{


//Local Definitions


char preFixExpr[256] = "-+*ABC/EF";


char postFixExpr[256] = "";





//Statements


cout %26lt;%26lt; "Begin prefix to postfix conversion\n\n";





preToPostFix (preFixExpr, postFixExpr);


cout %26lt;%26lt; "Prefix expr: " %26lt;%26lt; preFixExpr %26lt;%26lt; endl;


cout %26lt;%26lt; "Postfix expr: " %26lt;%26lt; postFixExpr %26lt;%26lt; endl;





cout %26lt;%26lt; "\nEnd prefix to postfix conversion\n";


return 0;


}// main





/*==================== preToPostFix ====================


Convert prefix expression to postfix format.


Pre preFixIn is string containing prefix expression


expression can contain no errors/spaces


postFix is string variable to receive postfix


Post expression has been converted


*/


void preToPostFix (char *preFixIn,


char *postFix)


{


//Local Definitions


char operatr [2];


char postFix1[256];


char postFix2[256];


char temp [256];


int lenPreFix;





//Statements


if (strlen(preFixIn) == 1)


{


*postFix = *preFixIn;


*(postFix + 1) = '\0';


return;


} // if only operand





*operatr = *preFixIn;


*(operatr + 1) = '\0';





// Find first expression


lenPreFix = findExprLen (preFixIn + 1);


strncpy (temp, preFixIn + 1, lenPreFix);


*(temp + lenPreFix) = '\0';


preToPostFix (temp, postFix1);





// Find second expression


strcpy (temp, preFixIn + 1 + lenPreFix);


preToPostFix (temp, postFix2);





// Concatenate to postFix


strcpy (postFix, postFix1);


strcat (postFix, postFix2);


strcat (postFix, operatr);





return;


}// preToPostFix





/*==================== findExprLen ====================


Determine size of first prefix substring in an expression.


Pre exprIn contains prefix expression


Post size of expression is returned


*/


int findExprLen (char *exprIn)


{


//Local Definitions


int lenExpr1;


int lenExpr2;





//Statements


switch (*exprIn)


{


case '*':


case '/':


case '+':


case '-':


// Find length of first prefix expression


lenExpr1 = findExprLen (exprIn + 1);





// Find length of second prefix expression


lenExpr2 = findExprLen (exprIn + 1 + lenExpr1);


break;


default:


// base case--first char is operand


lenExpr1 = lenExpr2 = 0;


break;


} // switch


return lenExpr1 + lenExpr2 + 1;


}// findExprLen

800flowers.com

I need help completing this C code. Basically it asks user for input String and reverses it and changes cases.

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





char* strRev(char* line);


//your code here


char* str2Lower(char* line);





main(void){


//your code here


while(opt != 4){


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


printf("\nCST220 --- Assignment 2\n");


printf("Joe Smith XXX-YY-ZZZZ\n\n");


printf("Please choose the type operation\n");


printf("1. Reverse an string\n");


printf("2. Change an string to upper case\n");


printf("3. Change an string to lower case\n");


printf("4. End application (Exit)\n");


printf("Option: ");


scanf("%d", %26amp;opt);





if(opt != 4 %26amp;%26amp; (opt %26gt;= 1 %26amp;%26amp; opt %26lt;= 3)){


printf("\n\nPlease enter the string: ");


//your code here


if(opt == 1){


printf("\nThe reversed string is : %s", strRev(str));


}


else if(opt == 2){


printf("\nThe string in uppercase: %s", str2Upper(str));


}


else if(opt == 3){


printf("\nThe string in lowercase: %s", str2Lower(str));


}


}


}


}


char* strRev(char* line){


//your code here


return str2;


}





char* str2Upper(char* line){


//your code here


return str2;


}





char* str2Lower(char* line){


//your code here


return str2;


}

I need help completing this C code. Basically it asks user for input String and reverses it and changes cases.
#include %26lt;ctype.h%26gt;





char* strRev(char* line) {


char *str2, first;


str2 = line+strlen(line)-1;


while (str2%26gt;line) {


first = line;


*line = str2;


*str2 = first;


line++;


str2--;


}


return str2;


}





char* str2Upper(char* line) {


while( *line ) {


*line = toupper(*line);


line++;


}


return line;


}





char* str2Lower(char* line) {


while( *line ) {


*line = tolower(*line);


line++;


}


return line;


}


How Do I Get The Class Location In C#, Dont Know How To Formulate Connection String?

In JAVA I used to use a class which told me where the class was located. I'm trying to tell the application that the database is in the solution but how do i do it?





I've got an OLEDB database, but i dont know how to formulate the connection string. The database is inside the Visual Studio solution but I dont know how to tell it that.





Please help...

How Do I Get The Class Location In C#, Dont Know How To Formulate Connection String?
Right click on your solution explorer and select properties. Go to the settings tab, type a name for a new setting (like DatabaseConnectionString) and select [Connection String] as the type. A wizard will popup allowing you to select a database; select your database. From now on, you can access this connection string using the Settings namespace, it would be:





Settings.Default.DatabaseConnectionStr...





I find this method much easier for doing this than remembering how to formulate the connection string. Adding the DB to your application solution really doesn't do anything for connecting to it.
Reply:OLEDB won't give you anything about the connectionstring. You dont really need to know where it is located.


I am using MYSQL database and when installed that MYSQL connector I just added it to each page i needed to work with MYSQL like this:





using MYSQL.data;





this way I get all the classes I need to connect and work with my database.


I hope this helps you


In C language , how can a string be printed to the console , with an empty main body ?? Impossible ??

Right now I can't come up with a way to do it in C.





In C++ you can do this:





class X


{


public:


X()


{


printf("Hello World!\n");


}


};





X x;





void main()


{


}





The constructor for x gets called before main is run.


I just tested this using VC6.0, and it works.

In C language , how can a string be printed to the console , with an empty main body ?? Impossible ??
It's been a long time since I've worked with C, but I believe that if you clear the screen then use the method





cout %26lt;%26lt; "String"





That'll do it... If that doesn't work, try changing the direction of the pointer.
Reply:You can use #error, but that will print a message at compile time. Some compilers also allow you to display a message via #pragma, but again, that's at compile time.





You can do something like this:


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





#define OBRACKET {printf("Hello world\n");


#define CBRACKET }





main()


OBRACKET


CBRACKET








Another option is use my example above, but substitute atexit(foo); for printf(), then declare function foo as such:


void foo()


{


printf("Test\n");


}





There might also be a way to do it in C++, but I'm not sure.


In C++, what's the term 'string' mean?

Please be as descriptive in English as possible I'm new at this stuff. Thanks :).

In C++, what's the term 'string' mean?
string or string functions?








String functions are used in computer programming languages to manipulate a string or query information about a string (some do both).





Most computer programming languages that have a string datatype will have some string functions although it should be noted that there may be other low level ways within each language to handle strings directly. In object oriented languages, string functions are often implemented as properties and methods of string objects. In both Prolog and Erlang, a string is represented as a list (of character codes), therefore all list-manipulation procedures are applicable, though the latter also implements a set of such procedures that are string-specific.





The most basic example of a string function is the length(string) function. This function returns the length of a string literal.





eg. length("hello world") would return 11.





Other languages may have string functions with similar or exactly the same syntax or parameters or outcomes. For example in many languages the length function is usually represented as len(string). The below list of common functions aims to help limit this confusion.
Reply:Strings are also dynamic in nature. With a normal character array, once you hit the end, you're done. With the string, you can just keep appending characters to it, and it allocates storage for them dynamically so you can hold as many as you want.





The [ ] operators are overloaded so you can treat it like a normal character array and access specific elements.
Reply:It is an array of characters. Nothing more, nothing less.





They just made this commonly used construct into a new class type called "string" which can be defined and used much easier than creating an array yourself.
Reply:group of characters....


characters- single letter, number or symbol....





=D

wildflower

Basically,what is string sorting?Can I get a C++ program to sort a string?

On what basis is the srting sorted out?In alphabetical order?

Basically,what is string sorting?Can I get a C++ program to sort a string?
I'm pretty sure you have to write a program to sort a string yourself. are you trying to make some letters in alphabetical order or what? all i can think of right now is using something like a bubble sort to compare the different parts(letters, words, whatever) of the string to each other... sorry for the bad answer! hope you figure everything out =3


Could anyone give me a C program to find substring from a string?

I kindly request U to give me the C program if U have,its Urgent.


I tried my level best but i dint get the result for some substring,


I Cant find out the logical error.So please help me.


Thanks in advance

Could anyone give me a C program to find substring from a string?
just use strstr.





Look at an open source copy of the code for strstr


Write a "c' prog to accept two string&prog should delete char similar in both the string&print remain strings

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





main( int argc, char **argv )


{


char *s1 = argv[1];


char *s2 = argv[2];


int i;


char *cp;


int count[256];





memset( count, 0, sizeof( count ) );


for( cp = s1; *cp; cp++ )


count[*cp]++;


for( cp = s2; *cp; cp++ )


count[*cp]++;





printf( "unique characters in s1: " );


for( cp = s1; *cp; cp++ )


if( count[*cp] == 1 )


printf( "%c", *cp );


printf( "\nunique characters in s2: " );


for( cp = s2; *cp; cp++ )


if( count[*cp] == 1 )


printf( "%c", *cp );


printf( "\n" );


}


I need to write a C++ Program that determines if a given string is a palindrome?

I need help with this program.








Hint





Create a string variable (char str[80])


Convert the string to uppercase characters


Keep only the alphabetic characters.


Compare the first character with the last character. If they're are the same,


compare the next character.

I need to write a C++ Program that determines if a given string is a palindrome?
#include%26lt;stdio.h%26gt;


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


#define size 26





void main()


{


char strsrc[size];


char strtmp[size];





clrscr();


printf("\n Enter String:= "); gets(strsrc);





strcpy(strtmp,strsrc);


strrev(strtmp);





if(strcmp(strsrc,strtmp)==0)


printf("\n Entered string \"%s\" ispalindrome",strsrc);


else


printf("\n Entered string \"%s\" is not


palindrome",strsrc);


getch();


}

tarot cards

The string of a piano that produces a middle c note vibrates with a frequency of 2.64x10(2) Hz.?

whats the speed of sound in air, if the sound waves produced by this string have a wavelength in air of 1.30m?

The string of a piano that produces a middle c note vibrates with a frequency of 2.64x10(2) Hz.?
Clue: what are the units of the Speed of sound? Meters/sec?





multiply the wavelentgh (m) by the frequency (sec^-1)





so 264 sec^-1 x 1.3 m = 343 m/s (1125 fps)





wer
Reply:beats the hell out of me. Ive been playing for 40 years. ( i have a failight and a babay grand a vox and a triton) been with bands for 25 years. Ive been considered a great touch and i can tune both the piano and figure out whats wrong electronically with my equipmetn. but i cant figure out why anyone would wantt o know this. except to waste his or her time. lol. seroiusly . just how much do you think the ear can hear? you remind me of the tone deaf singing. it just is chaotic and wrong. but if you make a better keyboard than whats out there. im all for it. ill play that too .though i cant imagine anyone noticing the difference. good luck!


The string of a piano that produces a middle "C" note vibrates with a frequency of 2.64x10(square root of 2)Hz

If the sound waves produced by this string have a wavelength in air of 1.30m, what is the speed of sound in air?

The string of a piano that produces a middle "C" note vibrates with a frequency of 2.64x10(square root of 2)Hz
The way that you typed the question has probably thrown everyone off. Middle C would be 264 Hz which can be written as 2.64 * 10². that is 'squared'; not 'square root'.





velocity = frequency * wavelength


= 264 * 1.30


= 343.2 metres per second.


Can u please give me an example of for loop,int,string and char?? in turbo c?

i need more some examples ...... please help me... so that I can review much in my coming exam.....

Can u please give me an example of for loop,int,string and char?? in turbo c?
Integer


any numbers from 0 to 9 you can feed in a int variable.


eg:


int year; - contains the numbers


year=1990;





String


A group of alpha(A-Z and a-z), numeric(0-9) and special characters kept in a variable is string.


eg.


string date;


date="19.02.2006";





char


each and every position in a string contains a char.


char usually contains only one letter.


char date_seperator;


date_seperator="/";





for loop


to repeat a operation for defined number of times use for loop.


eg. to print date starting from 0-30





int date=0;


string month="June";


String year="1990"


char date_seperator ="/";








for (date=0;date%26lt;=30;i++)


{


printf(date+date_seperator+month+date_...


}








hope this helps you to understand better. :)


In c++ how can I split a given string based on delimeter ?

For ex:


split (string , delimeter);


where split ("hello-world", "-")


returns "hello" and "world".








Thanks in advance.





-Maz

In c++ how can I split a given string based on delimeter ?
Use the function strtok





The function strtok is found in the C string library. It takes two arguments, both arrays of characters (i.e. arguments formally of type char *) which we will informally call strings





The first string is the string that we want to break up into tokens (in our case, that would be inString). The second string consists of a list of delimiters. These are characters which mark divisions between tokens.





When called, the function finds the first token in the string, marks the end of it with a \0 and returns a pointer to the start of that token. In other words, the return value is a string containing just the first token. Once we process that token and have finished with it, we can call strtok again. However this time we call it with a NULL pointer for the first string to indicate that we want the next token of the same original string. We proceed in this manner until strtok returns a NULL pointer, which indicates there are no more tokens left in the string to return.
Reply:#include%26lt;stdio.h%26gt;


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





char* split(char *str, char deli)


{


char *str2;


for(int i=0;str[i]!=deli;i++);


for(int j=i;str[j]!=NULL;j++)


{


str2[j-i]=str[j+1];


}


str2[j]=NULL;


str[i]=NULL;


return str2;


}





void main()


{


clrscr();


char *a = "Hello-World";


char *b = split(a,'-');


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


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


//*a will contain "Hello" And *b will contain "World".


getch();


}





i have not tested this code. i just made it ryt here for u only.
Reply:Does 'hello' and 'world' have to be two seperate strings?


If not, then all you have to do is look through the string, and replace the '-' with a space.


You don't need to use any functions on the string.


If it must be 2 strings from ONLY 2 words, then all you have to do is read each letter of a string and copy it to an array. You copy letters until you come to a '-' character. Then you add the number 0 to the array. Skip over the '-' and begin copying into another array until you get to the zero. Add the 0 to the second array. You must add a zero the the arrays because C/C++ strings are zero-terminated. If you tried to print a non-zero-terminated string, then your program could crash or there will be a lot of junk characters printed after the string.

secret garden

.Program in c++ to remove all spaces in a string. e.g. "love you all" should look like "loveyouall"

The string "loveyouall" should be stored in the same string and not in new one.

.Program in c++ to remove all spaces in a string. e.g. "love you all" should look like "loveyouall"
This should work:





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;


void stripSpace(string %26amp;);


int main() {


string test("HKLM\ Software\Microsfot\ Windows\Current Version\Run");


stripSpace(test);


cout %26lt;%26lt; test %26lt;%26lt; endl;


return 0;


}


void stripSpace(string %26amp;str) {


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


if (str[i]==' ') {


str.erase(i,1);


i--;


}


}





Enjoy :)
Reply:If u ve programmed in Turbo C++ this might be helpful..





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


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


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


int main(void)


{


char s[50];


cout %26lt;%26lt;"\nEnter String to Truncate: ";


gets(s);


int len = strlen(s),j=0;


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


{


if(isspace(s[i]))


{


j=i;


for(;j%26lt;len-1;j++)


s[j] = s[j+1];


if(i!=j)


{


s[j] = '\0';


len--;


}


}


}


cout %26lt;%26lt;"\n\nAfter Trunc: "%26lt;%26lt; s;


}


C++ How do you search through a string for a newline statement?

int count = 0;


string first;


while (text[count] != '/n')


{


first.push_back(text[count]);


count++;


}


cout %26lt;%26lt; endl %26lt;%26lt; first;





My compiler says I can't use the while statement because it is always true.

C++ How do you search through a string for a newline statement?
Hi - you're missing a "/" in your while statement.





the "/" statement is an escape character, and if you just say "/n", it sees it as part of the string. It's an impossible pattern in the string class, so it's always true. Try looking for "//n".





good luck -





Rob
Reply:Depends if you're using the String datatype or if you're using a character string thats ended with "/0" (I think). In your case it looks like you've got a character string.





You should be able to do:





int count = 0;


while( text[count] != '/0" )


{


if( text[count] == '/n' ) cout %26lt;%26lt; endl;


count++;


}





Or something like that. Not really sure what your objective is here.


C++ programming. My problems are with a String class.?

Good afternoon! :-)





How should I write it correctly?


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


2nd function: static void copy(String%26amp; string1, String string2); (it (I mean the second) copies the matter of string2 to string1)


The private members of the class are: unsigned int elementsNum; and char*pData; .


These were my "small" problems. My "big" problem is that I have to alter my program to be able to treat with UNICODE characters.





So, these (3) are my questions. Only one answer would help me a lot, so if you can answer just one of my questions, it would be lovely.





Thank you!!!





Domonkos

C++ programming. My problems are with a String class.?
(1) will end up being something like:





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


{


os %26lt;%26lt; pData;


}





3) has an obvious solution but non-trivial implementation - use templates, exactly like the STL has chosen to do. Write and get the class working for chars and then generalize it via templates to wchars and possibly alternate allocators.





2) This is harder to help you with without more info. What are your constructors, copy constructor, overloaded operators, append methods, etc., that you anticipate having in the class?
Reply:Hi,





This link may help you - http://www.jorendorff.com/articles/unico...





Also the book Win32 system programming has excellent explanation and examples on using unicode


http://www.amazon.com/gp/reader/02016346...


C-prog 2 chk if a given string is a palindrome using strrev?

actually the logic which i used was


char *s,*t ;


int x ;


printf("enter the string");


gets(s);


t=strrev(s);


x=strcmp(s,t);


if(x==0)


printf("palindrome");


else


printf("not palindrome");


getch();





the problem is that what ever string i enter the ouput says tht its a palindrome!!


friends ... plz help me out !!!???

C-prog 2 chk if a given string is a palindrome using strrev?
#include%26lt;stdio.h%26gt;


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





void main()


{


char s[20],t[20] ;


int x ;


printf("Enter the string : ");


gets(s);


strcpy(t,s);


strrev(s);


x=strcmp(s,t);


if(x==0)


printf("\nPalindrome");


else


printf("\nNot palindrome");


}





Actually strrev() reverses the original string,so in your program s %26amp; t were getting the same value irrespective of whatever you entered.Here I've copied the original value to t before reversing s.That solves your problem :)


also I would advise you not to use the gets() function as it is dangerous to use ,it may create problem in the memory structure,use scanf instead.
Reply:One major problem is in your program is you are using single character for s, and t; To declare string use





char s[10], t[10];


and modify your program accordingly














use strcmp() as follows


x=strcmp(*s, *t);
Reply:you r having x as integer and strcmp return %26lt;1or%26gt;1 if strings are not same so int converts a no like 0.something to zero,and string is always palindrome.just use statement


if(strcmp(s,t)) instead of putting value in x,it also decrease a variable in your program.
Reply:declare the char *s,*t as array


int s[10],t[10]


there u will get the perfect result.

pear

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

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

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





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





int GetValue(string data, int defaultValue)


{


int result = defaultValue;





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


catch { }





return result;


}
Reply:Something like this should work for you





public int convertStringToInt(string strSource)


{


try


{


return int.Parse(strSource);


}


catch


{


return null;


}





}


Thursday, July 30, 2009

How do i use a string variable with input file handle in c++ ?

usually what i do is:





ifstream InputFile;


InputFile.open("sample.txt");





but instead of using a file name i want to use a string variable. This is what I have tried:





stream x = "sample.txt";


ifstream InputFile;


InputFile.open(x);





but it is not working ? anybody got suggestions ??

How do i use a string variable with input file handle in c++ ?
you want to use a string type, not stream. check documentation on the C++ STL libraries.





string input = //whatever is from the user


ifstream infile;


infile.open( input.c_str() );





...





"c_str()" just returns a char* buffer to methods that need it.
Reply:ok so what you need to do is declare a char array of string not a stream varaible








stream x ="blah blah" // wrong








char * x;





x = new char[10]; // or however long your characters are





// then





x = "text.txt"





ifstream InputFile;


InputFile.open(x);





// this should work also remeber to pick the iso mode for it good luck


How can we print a string(eg"College") on the screen in C without using any semi colon.?

WE have to write the program code to display the string "College" on the output screen without making the use of any semi colon in the code.PLZ HLP

How can we print a string(eg"College") on the screen in C without using any semi colon.?
put it in an if.





like


main()


{


if(printf("College"))


{


;


}


}


this should work
Reply:That, or you can use inline ASM to call the "printf" function:





__asm


{


push [edx], DWORD PTR "College"


call printf


}





I believe. It's been a while since I've implemented inline ASM (did it with my last game engine).


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

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


char arr[20];


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


{


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


}

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





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





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


char line[100];


printf("Enter Binay String");


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





char ch;


char string[100];


int i=0;





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


{


ch = getchar();


string[i]=ch;


i++;


}

nobile

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

declare it as an array

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


What is the easiest way to determine if a string is a number in c#?

Convert.ToInt32()


will convert char's and strings





I am trying to get


Int32.TryParse(Console.ReadLine(), System.Globalization.NumberStyles.Intege... IFormatProvider, out searchZip);





..to work but wtf is an IFormat provider and is there a simple version of one that I can use or make?





...what is the simplest way to do this?





for my purposes 99999 is a number and 99,999 is not a number. wererewoiy definately is not a number.

What is the easiest way to determine if a string is a number in c#?
public static bool IsNumeric(object Expression)


{


bool isNum;


double retNum;


isNum = Double.TryParse(Convert.ToString(Express... System.Globalization.NumberStyles.Any,Sy... out retNum );


return isNum;


}





Try this


How do u implement string functions using pointers in C?

i need a sample program involving strcpy n strcat

How do u implement string functions using pointers in C?
#include %26lt;stdio.h%26gt;


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





main() {


char* a = "hello ";//a is a pointer to a string "hello "


char* b = "world";//b is a pointer to a string "world"


char string1[strlen(a)+strlen(b)+1];//string1 is a pointer to a string of characters





strcpy(string1, a);//string1 now cantains a "hello " string


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





strcat(string1, b);//string1 now cantains hello world


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


}
Reply:The code example by jericbryledy is incorrect because no space has been allocated for string1 to contain the copied characters.





use malloc to provide space for the copied characters.





string1 = (char *)malloc(sizeof(char) * (strlen(a) + 1));


strcpy(string1, a);


How do you tune a six string electric guitar in standard C? (C F Bb Eb G C)?

DOES ANYBODY KNOW!!!!!?????

How do you tune a six string electric guitar in standard C? (C F Bb Eb G C)?
if you're dropping the tuning, you'll need heavier gauge strings to make up for the decreased tension. i suggest ernie ball 'not even slinky' strings, they're designed for lowered tunings.





other than that, you just tune to whatever you want. this is easiest, of course, with an electronic tuner.
Reply:correct, just tune everything two steps down. you get an extreamly heavy sound. alot of guitars can't handle the looseness of the stings and it sounds out of tune, or the strings rattle on the fretboard
Reply:calm down the easyest way is to buy an electric guitar tuner. i got one at guitar center for 20 bucks.
Reply:why don't you go and get a electric tuner? it's cheap.

flower girl dresses

How do you print out the value in tstamp_t in C? Is it a string? Long?... Or do you have to break it apart?

Seems that you are asking from a reference guide. Probably that might be a variable the author used. Refer the previous pages of the book. The program should be carrying over from previous pages. Or try to give a piece of code here.

How do you print out the value in tstamp_t in C? Is it a string? Long?... Or do you have to break it apart?
The short answer: how are we suppose to know how to print it if we don't know what it is? It probably is some kind of time stamp but without the definition we can't know if it is a struct a typedef of some basic type or something else. Did it out and then someone can help you print it.


Please help me simulate this code in C source code?

simulate the string="COMPUTER" using the given pseudocode below:





Reverse (S)


{


Set N to the length of string S


If (N = 1) then


{


RETURN (S)


}


Else


{


Decrement N


RETURN (Reverse(SUBSTRING(S,2N)) || SUBSTRING(S,1,1)


}


}





***Please do this in a complete running source code in C language, thank you.

Please help me simulate this code in C source code?
Do your own homework.


How do you play a double flat c on the g string on the cello?

A double flat C would be a B-flat. On the G string, that 2nd finger (1st position).


In C++, how do I use either string or char to input first & last name using only one variable?

The console should ask for an author name, then the user enters both first and last name together (eg. John Doe), then the console should display both first and last name, but only one variable must be used. I've tried declaring char[20] or string but neither will allow for whitespace between the names. Any help is appreciated, thanks.

In C++, how do I use either string or char to input first %26amp; last name using only one variable?
#include %26lt;stdio.h%26gt;


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


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


#include %26lt;iostream%26gt;








using namespace std;





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


char name[80];





do{





int opcion;


cout%26lt;%26lt;"Selecione lo que desea hacer: "%26lt;%26lt;endl;


cout%26lt;%26lt;"Push 1 for put name %26amp; last name."%26lt;%26lt;endl;


cout%26lt;%26lt;"Push 2 for view the name %26amp; last name, you entered."%26lt;%26lt;endl;


cout%26lt;%26lt;"Push 3 for exit."%26lt;%26lt;endl;


cin%26gt;%26gt;opcion;


switch(opcion){


case 1:


cout%26lt;%26lt;"write the name and the lastname"%26lt;%26lt;endl;


/*jump exact 1 character used for the opcion*/


cin.ignore(1);


/*you can use cin.getline for take a chain of characters


con.getline take teh char array for put in came,


the number of characters , and the last the cahracter for delimited


*/


cin.getline(name,80,'\n');


break;


case 2:


cout%26lt;%26lt;"the name and the lastname youe entered are: "%26lt;%26lt;endl;


cout%26lt;%26lt;name%26lt;%26lt;endl;


break;





case 3:


exit(0);


break;


default:


cout%26lt;%26lt;" invalid"%26lt;%26lt;endl;


break;


}





}while(true);


return 0;


}





with cin.getline() you can take all the incomming data bye

flower garden

C: Why '&' not used to declare String or Character?

C questions. Pleas esend me this as early as possible





Regards





Varun

C: Why '%26amp;' not used to declare String or Character?
in c,%26amp; is used as a 'address of' operator,hence cannot be used to declare a character ,string and to declare u can use a pointer.
Reply:%26amp; symbol is a special symbol. You can give as a value for a string or a character. But any variable declartion should not start with symbols other than _(underscore). Usually %26amp; is used both as reference operator as well as "address operator". So it cant be used. Hope u understoold this.
Reply:%26amp; is a special charecter or symbol like $ # used as shortcuts
Reply:string in C is an array.


the symbol %26amp; can be represented as an character


char a='%26amp;';





a string example


char s[]="c%26amp;language";
Reply:%26amp; is address of operator in C


C++ programming, editing function to return string instead of char.?

This function used to return a single letter. How can I change it so it could return a string of 6 characters?





char pop(stack *s)


{


char pop;


pop=s-%26gt;cars[s-%26gt;top];


s-%26gt;cars[s-%26gt;top]='\0';


s-%26gt;top--;





return pop;


}

C++ programming, editing function to return string instead of char.?
Hi,





The variable name pop and function name cannot be same.


I suppose you are having a structure stack. something like this:





struc stack


{


char cars[10][7];


int top;


};





Also here I am considering u are using C language and want to store 10 cars each of whose name is of at the most of 6 characters.





char* pop_operation(stack *s)


{


char *pop;


pop=(char *)malloc(sizeof(char)*7); // In C++, use


// pop =new char[7];


strcpy(pop,s-%26gt;cars[s-%26gt;top]);


s-%26gt;cars[s-%26gt;top]='\0';


s-%26gt;top--;


return pop;


}








Where ever u r calling this function, note u have to declare a string pointer before by writing,





char *str;





and at the time of call as





str=pop_operation(strucure variable or pointer as u did earlier);





U can print it as u print other strings.





In case of further more clarifications, u may query me again.





OM NAMAH SHIVAY
Reply:What you are wanting to return is a C-String, or character array. Simply declare char pop as a array of 6 characters





char pop[5];





then fill the values into the pop array, and return the value when your done with the function.


How will you count the number of characters including space in a string or group of words using C language?

the output has to shown





enter the whole name: Juan DeLa Cruz





No.of characters shown: 14


No. of strings: 3





something like this....


i have no idea about this....just a little about string,i dont know where should i put those...








looking forward for the reply..

How will you count the number of characters including space in a string or group of words using C language?
Should be somethink like this (written in "project style") :





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





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


{


const unsigned length= 40;


char name[length]; /* declare the variable used to store the name */


unsigned chars=0, strings=0, blank=1; /* declare the counters */





printf("Enter the string :\n");


fgets(name,length,stdin); /* read the string name from the screen */





/* while loop to count chars and string - strlen would be easier but you probably may not use it as it's a project. Stop when it meets the end of the array */


while(name[chars]!='\n' %26amp;%26amp; name[chars]!='\0')


{


if (name[chars]==' ') blank=1; /* remove all the blanks and count them in chars, remembering that we're in a "blank" phase. in case there are many following like in " Juan de la Cruiz " */


else


{


if (chars==0 || blank==1)


{ /* if the first char isn't a blank or after all the blank trailing, we begin a new string in the sentence */


strings++;


blank= 0; /* we're not in a "blank phase" anymore */


}


}


chars++; /* in any case, we advance in the string name */


}


printf("\nNumber of characters in the string is=%d",chars);


printf("\nNumber of strings is=%d\n\n",strings);


}
Reply:Been awhile since I messed with c or c++ but I would count as 14 characters...


plus a null?


isn't there something that will tell you length of string?


strlen


http://www.opengroup.org/onlinepubs/0000...
Reply:strlen()


How to tune to C# on a 4 string bass?

is there anyone who can tell me in an easy way? i just started playing bass and i dont know how to do it

How to tune to C# on a 4 string bass?
im taking that ur tuning ur default E string to C# (the thickest string). Just tune it so it sounds like when the 4th fret on the 2nd thickest string is held and played.

edible flowers

Write a prog. in C to create a string of any length n replace SPACE and @ with % followed by their ASCII value

walk the original string, copying characters to a new string, if a


special character is encountered (SPACE or @) instead copy the ASCII value description.





Inefficient but easy to read--%26gt;





char string1[12] = "Hello World";


char string2[36] = ""; /* enough to convert every character! */





for (i=0, j=0; i%26lt;strlen(string1);i++)


{ if (string1[i] == ' ')


strcat(string2, "%20");


else if (string1[i] == '@')


strcat(string2, "%40");


else


strcat(string2, string1+i);


}





(did I remember the ascii values correctly?)


Write a prog. in C to create a string of any length n replace SPACE and @ with % followed by their ASCII value

walk the original string, copying characters to a new string, if a


special character is encountered (SPACE or @) instead copy the ASCII value description.





Inefficient but easy to read--%26gt;





char string1[12] = "Hello World";


char string2[36] = ""; /* enough to convert every character! */





for (i=0, j=0; i%26lt;strlen(string1);i++)


{ if (string1[i] == ' ')


strcat(string2, "%20");


else if (string1[i] == '@')


strcat(string2, "%40");


else


strcat(string2, string1+i);


}





(did I remember the ascii values correctly?)

Write a prog. in C to create a string of any length n replace SPACE and @ with % followed by their ASCII value
I once did this in C++, which is pretty similar to C. I replaced the word "dog" with the word "cat".





char sentence[100] = "I have a fat dog";


int step = 0;





for(step = 0, step %26lt;=100, step ++)


{





if (sentence[step] == 'd' %26amp;%26amp;


sentence[step + 1] == 'o' %26amp;%26amp;


sentence[step + 2] == 'g')


{


sentence[step] = "c";


sentence[step + 1] = "a";


sentence[step + 2] = "t";


}








}