Sunday, August 2, 2009

Guitar string. Find the speed of the standing wave on the string and tension the player must use.?

A 50 cm long guitar string with a mass per unit length of 3.20 g/m is in a room where the speed of sound in air equals 3.40 m/s. The guitar player wants to play a noted with a fundamental frequency of 356 Hz. (a) What is the wavelength of the sound wave producing this 356 Hz sound? (b) what is the speed of the standing wave on the guitar string? (c) How much tension must the guitar player use in this string in order to produce this note?

Guitar string. Find the speed of the standing wave on the string and tension the player must use.?
I'll assume you meant 340 m/s for the speed of sound:





a) λ = u/f = 340/356 = .955 m





c) T = 4µ*f²*L² = 4*.0032*356²*.5² = 405.55 N





b) u = √(T/µ) = √(405.55/.0032) = 356 m/s

edible flowers

How do i make a program in c language that encrypt vowel in a string?

ex: if i input hello the output would be h*ll0

How do i make a program in c language that encrypt vowel in a string?
#include %26lt;stdio.h%26gt;


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


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





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


{


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


const char szEVowels[]={'@','*','#','0','^'};


char szBuff[100];








printf("Enter string%26gt;%26gt; ");


gets(szBuff);





//iterate thru the input string


for (int ctr=0;ctr%26lt;(int)strlen(szBuff);ctr++)


{


//iterate thru the vowels array


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


{





if (szBuff[ctr] == szVowels[x])


szBuff[ctr]= szEVowels[x];


}





}


printf("New string is: %s",szBuff);


getch();


return 0;


}


How do i make a program in c language that encrypt vowel in a string?

example when i input hello the output will be h*ll0

How do i make a program in c language that encrypt vowel in a string?
#include %26lt;stdio.h%26gt;


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





void mask_vowels(char* chars, size_t len)


{


size_t i;


size_t j;


char source_chars[] = "aeiou";


char replace_chars[] = "@*!0%";





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


{


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


{


if (chars[i] == source_chars[j])


{


chars[i] = replace_chars[j];


break;


}


}


}


}





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


{


// This is just to test that it works, try to replace the chars in the first command line argument and print out the results


if (argc %26gt; 1)


mask_vowels(argv[1], strlen(argv[1]));





printf("%s\n", argv[1]);


}








Just make source_chars and replace_chars are the same size if you change them.
Reply:Create a function that will accept a string and return another string. The function will examine the passed string byte-by-byte. A case structure can echo non-vowels to the return string and replace vowels in whatever manner you want - either a 1-for-1 replacement with the same character replacing the same vowel each time or a random replacement. When the entire passed string has been processed, return the modified string.


How can we get a string & reverse it ? without using pointers & arrays in C / C++?

/*i think its impossible to do without using arrays as string is an array of characters but it is possible to do without using pointers*/


void main()


{





char s[10],b[10];int x,k,i;


clrscr();


printf("enter a string\n");


gets(s);


x=strlen(s);


k=0;


for(i=x;i%26gt;0;i--)


{


b[k]=s[i-1];


k++;


b[k]='\0';


}


printf("the reversed string of %s is %s",s,b);


getch();


}

How can we get a string %26amp; reverse it ? without using pointers %26amp; arrays in C / C++?
Technically this is impossible because a string is a char array in c and an object representing a char array in c++. Therefore you MUST use arrays, and to access an array you need a pointer, consider:





char myArray[3]={0, 0, 0};


myArray[2]=3;





this is eqivelent to:





char myArray[3]=(0, 0, 0);


*(myArray+3)=0;





So to reverse a string use something like this:





string reverse(string str)


{


string result="";


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


{


result+=str[a];


}


return result;


}


C# & visual studio, what is the difference between string & String?

from the point of view of writing programs there's not much difference.


The difference is where the two data types come from.


There are two types of data types in C#. One that is the part of language itself, and the other it borrows from Dot Net Common Language Infrastructure (CLI).


The data type "string" is a part of C# language definition. i.e. it is a valid type in C# only not in C++ dot net or anything.


Whereas, "String" is a part of CLI. i.e. it is valid type in all other language supporting Dot Net.


It's the same as in difference between "int" and "Int32"

C# %26amp; visual studio, what is the difference between string %26amp; String?
Actually, I'm pretty sure 'String' is the same thing as 'string' because you can use them interchangeably. The only other difference is that string gets a dark blue coloring while String gets a nice, pleasant aqua-blue coloring in the IDE, which is why I prefer it.
Reply:They are the same. string is an alias to String. To be more accurate, String is the name of the data type in the Framework. string is the keyword in C#.





This is similar to comparing int to System.Int32 or bool to System.Boolean.





Thank You.

covent garden

C++ Question, Strings?

How can i get the last letter of a string in C++?


ex. input = "hi", output = "i"

C++ Question, Strings?
http://cppreference.com/cppstring/length...





You can use an indexer on strings, so the last letter is at length -1.
Reply:char lastchar(string s)


{


if (( s == null ) || ( s.length() == 0 ))


return '\0';





return s[ s.length() - 1 ];


}
Reply:Hello dear,


The first answer is written in C# !


this is C++ code for your question:





char *c ;


gets(c);


int i=strlen(c);


cout%26lt;%26lt;c[i-1]; //Because index of array members in C start from 0





Good Luck , Hossein
Reply:From what I remember you check next character and if it a null or space then output current.
Reply:try this code


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


{


if(i==str.lenght())


cout%26lt;%26lt;str[i];


}


Strings in C#?

if a user enters the expression in a textbox e.g 3 + 5


what is the code in c# that will take the string and evaluate


the expression?

Strings in C#?
See the code here:


http://www.codeproject.com/KB/cs/evalcsc...





It shows how to implement an "eval" function that inputs a string and evaluates it as code. If it's added to your project with the imports, you could do something like:





MessageBox.Show(eval("3+4;").toString(...





If all you need to do is add numbers though, it's overkill and it would be better to scan through the string for the "+" and extract the numbers on opposite sides.
Reply:Tryparse(textBox1-%26gt;Text,num1);


Tryparse(textBox2-%26gt;Text;num2);


num3=num1*num2;





textBox3-%26gt;Text=num3.toString();


or


MessageBox(num3.toString());

email cards

Do u know, in c++ programming, how I can infile a string which has exactly n characters in it? I appreciate it

If you use fopen for the stream you could do an fread to read a specific number of bytes from the stream.


How to write C program for finding reverse of a string?

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


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


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





void main()


{


char *str,*rev;


int n,i,cnt=0;


n=strlen(str);





printf ("Enter any string : ");


gets(str);





for (i=n; i%26lt;=0 ;i--)


{


rev[cnt]=str[i];


cnt++;


}


rev[cnt]='\0';





printf ("\n\nReverse string : %s",rev);


getch();


}

How to write C program for finding reverse of a string?
this sounds like homework, so I'll just give you an idea.





put the string in an array.





ie "string"





s[0] = 's'


s[1] = 't'


s[2] = 'r'


s[3] = 'i'


s[4] = 'n'


s[5] = 'g'





make a variable, say x, the size of the array. output the string backwards, starting from x while x %26gt;= 0.





5 - g


4 - n


3 - i


2 - r


1 - t


0 - s


Write program in c which will which will read a string & rewrite it in the alphabetical order?

ask again in Computer software section .... not authors

Write program in c which will which will read a string %26amp; rewrite it in the alphabetical order?
What he said..then a bunch of if-then commands.


Write a c++ program that convert numeric value to string?

for example:


input: 190.65


output:one hundred ninety and sixty five

Write a c++ program that convert numeric value to string?
Step 1: Convert floating point number to a string using these samples


http://www.cprogramming.com/tips/showTip...


http://www.codeguru.com/forum/showthread...





i.e., 190.65 to





convertedStr = "190.65";





Step 2: Have an array of strings like


text[0] = "";


text[1] = "one";


text[2] = "two";


text[3] = "three";





and lookup for each char in the converted string:





if(convertedStr[0] == '1') output = text[1];

cheap flowers

Estimate the force a person must exert on a string attached to a 0.100 kg ball to make the ball revolve in a c

Estimate the force a person must exert on a string attached to a 0.100 kg ball to make the ball revolve in a circle when the length of the string is 0.600 m. The ball makes 1.40 revolutions per second. Do not ignore the weight of the ball. In particular, find the magnitude of FT, and the angle it makes with the horizontal. [Hint: Set the horizontal component of FT equal to maR; also, since there is no vertical motion, what can you say about the vertical component of FT?]

Estimate the force a person must exert on a string attached to a 0.100 kg ball to make the ball revolve in a c
Fg = mg = (0.10 kg)(9.8 m/s^2) = .98 N


Fc = (mv^2)/r = mrω^2


Fc = (0.10 kg)(0.60 m)((2π rad/s)^2


Fc = (0.10 kg)(0.60 m)((2π 1.4)^2


Fc = 4.64 N


Ft = √( 4.64^2 + .98) = 4.74N


@ arctan(.98/4.74)


Ft ≈ 4.74N @ 11.68°





Did u get number 6 ??


Can u plz help to write a c program to print number of lines,words,characters and spaces in a given string?

using string function or any other functions

Can u plz help to write a c program to print number of lines,words,characters and spaces in a given string?
Tutorial Section:





Here is a toy program for computing your car's gas mileage. It asks you for the distance driven on the last tank of gas, and the amount of gas used (i.e. the amount of the most recent fill-up). Then it simply divides the two numbers.


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


#include %26lt;stdlib.h%26gt; /* for atoi() */





int getline(char [], int);





int main()


{


char inputline[100];


float miles;


float gallons;


float mpg;





printf("enter miles driven:\n");


getline(inputline, 100);


miles = atoi(inputline);





printf("enter gallons used:\n");


getline(inputline, 100);


gallons = atoi(inputline);





mpg = miles / gallons;


printf("You got %.2f mpg\n", mpg);





return 0;


}





int getline(char line[], int max)


{


int nch = 0;


int c;


max = max - 1; /* leave room for '\0' */





while((c = getchar()) != EOF)


{


if(c == '\n')


break;





if(nch %26lt; max)


{


line[nch] = c;


nch = nch + 1;


}


}





if(c == EOF %26amp;%26amp; nch == 0)


return EOF;





line[nch] = '\0';


return nch;


}





For each of the two pieces of information requested (mileage and gallons) the code uses a little three-step procedure: (1) print a prompt, (2) read the user's response as a string, and (3) convert that string to a number. The same character array variable, inputline, can be to hold the string used both times, because we don't care about keeping the string around once we've converted it to a number. The function for converting a string to an integer is atoi. (The compiler then automatically converts the integer returned by atoi into a floating-point number to be stored in miles or gallons. There's another function we could have used, atof, which converts a string--possibly including a decimal point--directly into a floating-point number.)





You might wonder why we're reading the user's response as a string, only to turn around and convert it to a number. Isn't there a way to read a numeric response directly? There is (one way is with a function called scanf), but we're going to do it this way because it will give us more flexibility later. (Also, it's much harder to react gracefully to any errors by the user if you're using scanf for input.)





Obviously, this program would be a nuisance to use if you had several pairs of mileages and gallonages to compute. You'd probably want the program to prompt you repetitively for additional pairs, so that you wouldn't have to re-invoke the program each time. Here is a revised version which has that functionality. It keeps asking you for more distances and more gallon amounts, until you enter 0 for the mileage.


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


#include %26lt;stdlib.h%26gt; /* for atoi() */





int getline(char [], int);





int main()


{


char inputline[100];


float miles;


float gallons;


float mpg;





for(;;)


{


printf("enter miles driven (0 to end):\n");


getline(inputline, 100);


miles = atoi(inputline);





if(miles == 0)


break;





printf("enter gallons used:\n");


getline(inputline, 100);


gallons = atoi(inputline);





mpg = miles / gallons;


printf("You got %.2f mpg\n\n", mpg);


}





return 0;


}





The (slightly) tricky part about writing a program like this is: what kind of a loop should you use? Conceptually, it seems you want some sort of a while loop along the lines of ``while(miles != 0)''. But that won't work, because we don't have the value of miles until after we've prompted the user for it and read it in and converted it.





Therefore, the code above uses what at first looks like an infinite loop: ``for(;;)''. A for loop with no condition tries to run forever. But, down in the middle of the loop, if we've obtained a value of 0 for miles, we execute the break statement which forces the loop to terminate. This sort of situation (when we need the body of the loop to run part way through before we can decide whether we really wanted to make that trip or not) is precisely what the break statement is for.


Next, we're going to write our own version of the atoi function, so we can see how it works (or might work) inside. (I say ``might work'' because there's no guarantee that your compiler's particular implementation of atoi will work just like this one, but it's likely to be similar.)


int myatoi(char str[])


{


int i;


int digit;


int retval = 0;





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


{


digit = str[i] - '0';


retval = 10 * retval + digit;


}





return retval;


}





You can try this function out and work with it by rewriting the gas-mileage program slightly to use it. (Just replace the two calls to atoi with myatoi.)





Remember, the definition of a string in C is that it is an array of characters, terminated by '\0'. So the basic strategy of this function is to look at the input string, one character at a time, from left to right, until it finds the terminating '\0'.





The characters in the string are assumed to be digits: '1', '5', '7', etc. Remember that in C, a character's value is the numeric value of the corresponding character in the machine's character set. It turns out that we can write this string-to-number conversion code without knowing what character set our machine uses or what the values are. (If you're curious, in the ASCII character set which most machines use, the character '0' has the value 48, '1' has the value 49, '2' has the value 50, etc.)





Whatever value the character '0' has, '0' - '0' will be zero. (Anything minus itself is 0.) In any realistic character set, '1' has a value 1 greater than '0', so '1' - '0' will be 1. Similarly, '2' - '0' will be 2. So we can get the ``digit'' value of a character (on the range 0-9) by subtracting the value of the character '0'. Now all we have to do is figure out how to combine the digits together into the final value.





If you look at the number 123 from left to right, the first thing you see is the digit 1. You might imagine that you'd seen the whole number, until you saw the digit 2 following it. So now you've seen the digits 1 2, and how you can get the number 12 from the digits 1 and 2 is to multiply the 1 by 10 and add the 2. But wait! There's still a digit 3 to come, but if you multiply the 12 by 10 and add 3, you get 123, which is the answer you wanted. So the algorithm for converting digits to their decimal value is: look at the digits from left to right, and for each digit you find, multiply the number you had before by 10 and add in the digit you just found. (When the algorithm begins, ``the number you had before'' starts out as 0.) When you run out of digits, you're done. (The code above uses a variable named retval to keep track of ``the number you had before'', because it ends up being the value to be returned.)





If you're not convinced that this algorithm will work, try adding the line


printf("digit = %d, retval = %d\n", digit, retval);





at the end of the loop, so you can watch it as it runs.





The code above works correctly as long as the string contains digits and only digits. But if the string contained, say, the letter 'Q', the code would compute the value 'Q' - '0', which would be a meaningless number. So we'd like to have the code do something reasonable if it should happen to encounter any non-digits (that is, if someone should happen to call it with a string containing non-digits).





One way for the string to contain non-digits is if it contains any leading spaces. For example, the string " 123" should clearly be converted to the value 123, but our code above wouldn't be able to do so. One thing we need to do is skip leading spaces. And the other thing we'll do (which isn't perfect, but is a reasonable compromise) is that if we hit a non-space, non-digit character, we'll just stop (i.e. as if we'd reached the end of the string). This means that the call myatoi("123abc") will return 123, and myatoi("xyz") will return 0. (As it happens, the standard atoi function will behave exactly the same way.)





Classifying characters (space, digit, etc.) is easy if we include the header file %26lt;ctype.h%26gt;, which gives us functions like isspace which returns true if a character is a space character, and isdigit which returns true if a character is a digit character.





Putting this all together, we have:


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





int myatoi(char str[])


{


int i;


int retval = 0;





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


{


if(!isspace(str[i]))


break;


}





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


{


if(!isdigit(str[i]))


break;


retval = 10 * retval + (str[i] - '0');


}





return retval;


}





(You may notice that I've deleted the digit variable in this second example, because we didn't really need it.)





There are now two loops. The first loop starts at 0 and looks for space characters; it stops (using a break statement) when it finds the first non-space character. (There may not be any space characters, so it may stop right away, after making zero full trips through the loop. And the first loop doesn't do anything except look for non-space characters.) The second loop starts where the first loop left off--that's why it's written as


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





The second loop looks at digits; it stops early if it finds a non-digit character.





The remaining problem with the myatoi function is that it doesn't handle negative numbers. See if you can add this functionality. The easiest way is to look for a '-' character up front, remember whether you saw one, and then at the end, after reaching the end of the digits and just before returning retval, negate retval if you saw the '-' character earlier.


Here is a silly little program which asks you to type a word, then does something unusual with it.


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





extern int getline(char [], int);





int main()


{


char word[20];


int len;


int i, j;





printf("type something: ");


len = getline(word, 20);





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


{


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


printf(" ");


printf("%s\r", word);


}


printf("\n");





return 0;


}


(To understand how it works, you need to know that \r prints a carriage return without a linefeed.) Type it in and see what it does. (You'll also need a copy of the getline function.) See if you can modify the program to move the word from right to left instead of left to right.











Exercises:





Type in the character-copying program from section 6.2 of the notes, and run it to see how it works. (When you run it, it will wait for you to type some input. Type a few characters, hit RETURN; type a few more characters, hit RETURN again. Hit control-D or control-Z when you're finished.)


Type in the getline() function and its test program from section 6.3 of the notes, and run it to see how it works. You can either place getline() and its test program (main()) in one source file or, for extra credit, place getline() in a file getline.c and the test program in a file getlinetest.c (or perhaps gtlntst.c), for practice in compiling a program from two separate source files.


Rewrite the getline test program from Exercise 2 to use the loop


while(getline(line, 256) != EOF)


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





That is, have it simply copy a line at a time, without printing ``You typed''. Compare the behavior of the character-copying and line-copying programs. Do they behave differently?





Now rewrite the character-copying program from Exercise 1 to use the loop


while((c = getchar()) != EOF)


printf("you typed '%c'\n", c);





and try running it. Now do things make more sense?


The standard library contains a function, atoi, which takes a string (presumably a string of digits) and converts it to an integer. For example, atoi("123") would return the integer 123.





Write a program which reads lines (using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. (Like the example programs in the notes, it should determine the end of ``all the numbers read'' by checking for EOF.) See how much of the code from assignment 3, exercise 7 you can reuse (if you did that exercise). Remember that integer division truncates, so you'll have to declare some of your variables as float or double.





For extra credit, also compute the standard deviation (see assignment 3, exercise 7).


Write a rudimentary checkbook balancing program. It will use getline to read a line, which will contain either the word "check" or "deposit". The next line will contain the amount of the check or deposit. After reading each pair of lines, the program should compute and print the new balance. You can declare the variable to hold the running balance to be type float, and you can use the function atof (also in the standard library) to convert an amount string read by getline into a floating-point number. When the program reaches end-of-file while reading "check" or "deposit", it should exit. (In outline, the program will be somewhat similar to the average-finding program.)





For example, given the input


deposit


100


check


12.34


check


49.00


deposit


7.01





the program should print something like


balance: 100.00


balance: 87.66


balance: 38.66


balance: 45.67











Extra credit: Think about how you might have the program take the word "check" or "deposit", and the amount, from a single line (separated by whitespace).


Rewrite the ``compass'' code from Assignment 2 (exercise 4) to use strcpy and strcat to build the "northeast", "southwest", etc. strings. (Don't worry about capitalizing them carefully.) You should be able to write it in a cleaner way, without so many if's and else's. Remember to declare the array in which you build the string big enough to hold the largest string you build (including the trailing \0).


Write a program to read its input, one character at a time, and print each character and its decimal value.


Write a program to read its input, one line at a time, and print each line backwards. To do the reversing, write a function


int reverse(char line[], int len)


{


...


}





to reverse a string, in place. (It doesn't have to return anything useful.)


In turbo c programming how can i make a string appear in the center like a marquee?

i want you to answer in details

In turbo c programming how can i make a string appear in the center like a marquee?
here is a simple example, modify it as you want


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


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


void main()


{


int i;


clrscr();


getch();


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


{


textcolor(BLACK);


gotoxy(i-1,10);


cprintf("Sachin");


textcolor(GREEN);


gotoxy(i,10);


cprintf("Sachin");


delay(50);


}


getch();


}


How do i calculate the length of the string without using the strlen function in c++?

Loop on every char of the string until you hit '\0'

How do i calculate the length of the string without using the strlen function in c++?
#include%26lt;iostream.h%26gt;


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


void main()


{


int i;


char j[21];//WILL STORE 20 CHARS,LAST CHAR FOR NULL


clrscr();


cout%26lt;%26lt;"\nENTER STRING";


cin.getline(j,21);


i=0;


while(j[i]!=NULL)


i++;


cout%26lt;%26lt;"\nLENGTH OF STRING IS %d"%26lt;%26lt;i;


getch();


}
Reply:Use a loop counter until you reach the end.
Reply:#include%26lt;iostream.h%26gt;


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


void main()


{


char test[ ]="This is a test string";


int i=0;


while(test[ i ]) // The Loop continues till test[ i ] is NOT Null


{


i++; //increments i , also counts character


}


cout%26lt;%26lt;"Length of test string is "%26lt;%26lt;i-1; // i-1 because i is the number including NULL


getch();


}
Reply:tape measure

baseball cards

C problem When I'm deleting a string and print it. it doesnt prints blank it prints unknown characters.?

I want to print it blank and not unknown characters

C problem When I'm deleting a string and print it. it doesnt prints blank it prints unknown characters.?
How are you "deleting" the string? I'm a little rusty at C but if I recall correctly strings cant be changed or anything. You probably end up having a pointer to some weird memory address. I believe there is a better class for handling strings called BufferedString. Try using that class instead and see if you still have the weird character problem.
Reply:How are you deleting the string? I'm pretty sure it's doing this because the method you are using is erasing the variable array but not the memory location. It's either that or the string has been set to null.





The next question is, if you just want to cout or printf blank, why not just set the array to all spaces or something?
Reply:Three things come to mind:





1) You are printing something out that doesn't have any meaningful memory assigned to it. Off the top of my head:





int array[4], i;


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


array[i] = i;


}


printf("Something %d\n", array[4]);





What's happening here is that the array index 4 doesn't point to anything in particular, whatever happened to be lurking in memory there would get output.





2) You actually want to print out spaces:





printf(" ");





would actually print out a blank space.





3) You want to backspace over something that you've output before.





printf("\b");





will print a backspace character. This should "back up" over one character that you've previously printed.


I have to inpu integer for c++ code how can i check whether the user input integer or a string character if ..

the user input a string character how to promt him ro enter integer again

I have to inpu integer for c++ code how can i check whether the user input integer or a string character if ..
there are functions available in ctype.h header


isalph()


isalnum()


isdigit()


use them


Write a programme that find the given string is plain order or not in C language?

????does not make any sense

Write a programme that find the given string is plain order or not in C language?
your gonna have to reword that question..."...given string is plain order or not..." what does that mean?


Write a c program to print the answer of a task which is given as a single string as a value?

for eg:- if we give 5+3 as an expression the output should be 8


that is sum of the given expression


not by reading each character into one variable.


the input should be into one single string

Write a c program to print the answer of a task which is given as a single string as a value?
Here are some links:


http://finance-old.bi.no/~bernt/gcc_prog


http://howstuffworks.com/c.htm


http://www.cs.cf.ac.uk/Dave/C/CE.html

artificial flowers

How to detect if a string has a space in it in C++?

If it is a C++ string you can use the find or the rfind functions. The find function returns the position of a substring from the left to right and the rfind from the right to left. Both return string::npos if the substring is not found. You can then test





if(s.find(" ") != string::npos)


// there is a space on the string


// do something


{





}

How to detect if a string has a space in it in C++?
You've gotta scan through each character one by one until you reach the end or find a space.





You can use wcschr to do that:





// use const char * for ANSI strings


bool contains_a_space(const wchar_t *s)


{


// use strchr(s, ' ') for ANSI strings


return wcschr(s, L' ') != NULL;


}





For std::wstring then you can do...





// use std::string for ANSI strings


bool contains_a_space(const std::wstring %26amp;s)


{


// use s.find(' ') for ANSI strings


return s.find(L' ') != -1;


}
Reply:hmmm, my mind is cloudy right now, this isspace() function works but it's for char in the cctype library, you can always make a strange a char by declaring it like this:





char anything[64];





the 64 is the amount of space expected, you can make it larger, can't remember if you can leave it blank and it self detects.





here is something i wrote a long time ago, it counts characters, spaces, i dunoo what else in a text file, perhaps this will help you:





#include %26lt;iostream%26gt;





#include %26lt;fstream%26gt;





#include %26lt;cstdlib%26gt;











int main()





{





using namespace std;











ifstream fin;





ofstream fout;





char in_file[32], out_file[32], character;





int alpha_count(0), white_count(0), nonwhite_count(0), total(0);











cout %26lt;%26lt; "Please enter filename to read from: ";





cin %26gt;%26gt; in_file;





cout %26lt;%26lt; "Please enter filename to write to: ";





cin %26gt;%26gt; out_file;











fin.open(in_file);





if (fin.fail())





{





cout %26lt;%26lt; "Opening input file failed. \n";





system("pause");





exit(1);





}











fout.open(out_file);











while (! fin.eof())





{





fin.get(character);











if (isalpha(character))





alpha_count++;





else if (isspace(character))





white_count++;





else





nonwhite_count++;





}











total = alpha_count + white_count + nonwhite_count;











cout %26lt;%26lt; "The total count of characters is " %26lt;%26lt; total %26lt;%26lt; endl





%26lt;%26lt; "Total count of non-whitespace characters is " %26lt;%26lt; nonwhite_count + alpha_count %26lt;%26lt; endl





%26lt;%26lt; "Total count of lettere is " %26lt;%26lt; alpha_count %26lt;%26lt; endl %26lt;%26lt; endl;











fout %26lt;%26lt; "The total count of characters is " %26lt;%26lt; total %26lt;%26lt; endl





%26lt;%26lt; "Total count of non-whitespace characters is " %26lt;%26lt; nonwhite_count + alpha_count %26lt;%26lt; endl





%26lt;%26lt; "Total count of lettere is " %26lt;%26lt; alpha_count %26lt;%26lt; endl %26lt;%26lt; endl;











fin.close();





fout.close();











system("pause");





return 0;





}





------notes------





this is the complete program, you can cut and paste it to run it, when you indicate the file make sure to put .txt





hope that helps.





hope there isn't many errors, i wrote that for a class i was taking a long time ago.


How to swap to string variables without using third variable in c# or vb.net?

VB.NET





a %26amp;= b


b = a.Substring(0, a.Length - b.Length)


a = a.Substring(b.Length)

How to swap to string variables without using third variable in c# or vb.net?
It is String so in C# we can proceed like this





String name1 = "Yahoo";


String name2 = "Answers";








name1 = name1 + name2;





name2 = name1.substring(0,


(name1.length() - name2.length()));





name1 = name1.substring(name2.length() , name1.length());
Reply:For this you can use xor to swap





a = a^b


b= a^b


a= a^b





Lets take an more example:





A = 01111111


B = 01111101





A = A^B = 00000010


B = A^B = 01111111 (Original A)


A = A^B = 01111101 (Original B)


Passing strings in C?

I'm pretty new to C and need help with strings. I also have no idea about the differences between C and C++, so please only help with info on C and not C++ or C#.





If I created a string in a function and want to pass it as a return value for the function to use in other functions, how can I do this without loosing the string when the function ends?





I know that when a function ends, everything that is local to it gets, for a better word, destroyed. If you can only return/pass the pointer to the string created in the function, when the function ends, won't the actual string be destroyed/reallocated and the pointer be essentially useless? How can I return the actual string/keep it for use in other functions?

Passing strings in C?
ok.... you have the basics right. so this is what you need to do





char * foo() {


int str_size = 6; //example size.


char * x = (char *) malloc(sizeof(char)*str_size);


sprintf(x, "%s", "hello");


return x;


}





the malloc is allocation memory from the heap. this will ensure that even when you exit the foo method, the location is not reclaimed. And you return the address to the same.


So you should be fine.
Reply:but don't forget to free() the pointer when you don't need it anymore, otherwise you will have a memory leak.


A function in C that will count the number of a certain character from a string of characters from the input.?

The user must be able to enter a string of any amount of characters and the output must count only one specific character. Thank you.

A function in C that will count the number of a certain character from a string of characters from the input.?
there is a string function that will do that, I just cant remember what its called. look in the string.h file, or documentation you have for the string functions.





another way is as the other person said. its a pretty easy routine to write, just try it.
Reply:An if statement iterating through the string until it finds the null.... A simple counter variable with an if statement that adds one to the counter every time target is found...

800flowers.com

How to write a C progamming language that uses a stack to determine if a string palindrome.?

palindrome is a word or phrase which reads the same in both directions.the program should ignore spaces %26amp; punctuation. example or word palindrome is:RACECAR, DEED, LEVEL,PIP,ROTOR,CIVIC,POP, MADAM,EYE,NUN,RADAR,TOOT.Example of phrase palindrome is:LIVE EVIL %26amp; STRAW WARTS. Can anyone help me to write the C programming URGENT.TQ

How to write a C progamming language that uses a stack to determine if a string palindrome.?
It says he has to do it using a stack. Basically you have to create some sort of stack data structure if you don't have one at your disposal. I would just use a linked list and then you need to implement the push, pop, and peek functions that manipulate your linked list. Next you take the word and push each character onto the stack starting at the first character going towards the end. Then you iterate through the input string starting at the end and going towards the beginning. At each character you pop off one character from the stack and compare it to the current character. If they are not equal exit your loop because the input is not a palindrome.
Reply:You need two strings arrays str1[] and str1[]


resverse the str1[] into str2[] and check them for equlance


if(strcmp(str1, str2)==0)


printf("\n String is Plaindrome");


else


printf("\n Not a Palindrome");





strcmp() is used to comapre two strings, it returns 0 if both strings are equal.


What causes this warning in C? warning: cannot pass objects of non-POD type 'struct std::string' through...

warning: cannot pass objects of non-POD type 'struct std::string' through '...'; call will abort at runtime

What causes this warning in C? warning: cannot pass objects of non-POD type 'struct std::string' through...
You are probably trying to pass on a value of a string to a nonstring variable. For example, if you define a variable as an integer and then make it equal a string, it will give you that error.





~WhoCares357


C++: How can I store each word from a sentence as an individual string?

If I ask the user to input a sentence, how can I store each word from that sentence as an individual string? I then want to push each word into a queue, so it's not important that I permanently store each word in a separate variable.

C++: How can I store each word from a sentence as an individual string?
Each word is separated by a space. Hence, your objective is tokenize a string (using spaces), and then store those tokens appropriately.





Since this is C++, I'm assuming you have the sentence in a C++ string. Look at http://www.oopweb.com/CPP/Documents/CPPH... and more specifically the string tokenizer section. If you're not familiar with the various C++ string methods look at http://cppreference.com/cppstring/index....








Specifically the logic is this:


Keep looking for the first space in the string you encounter. Obviously, everything from your current position in the string to the first occurence of the space is the word itself. Therefore, that is your token. Move your current position over to where the space is. Repeat the look for the next space process if you haven't reached the end of the string.





Work through the string tokenizer code and you'll understand.
Reply:use argv[]


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

i need this program for a assignment

I need to write a C++ program that determines if a string is a palindrome?
Set up a for loop starting at the length of the string and moving backward one character at a time until you reach the first character.





Inside the loop copy the character you are at to the end of a new string which you dimensioned the same size as the original .





When you reach the end of the first string all of the characters should be copied in reverse order to the second string.





Now just compare your original string to the new string if they are equal then the original sting was a palindrome.
Reply:This should not be too bad. I don't know c++ at all, but you should be able to loop on the number of letters in the string. Here is some pseudo-code





if (n is odd) // n is the length of the string


{lengthToCheck = (n-1)/2}


else


{lengthToCheck = n/2}


endif





palindrome = true


for i= 1 to lengthToCheck


{if(i-th element in string %26lt;%26gt; n+1-i-th element in string) then


{palindrome = false


exit(false)


}


}





That should do it. Hope this is helpful from someone who knows very little C++ code.

wildflower

How do i read in arrays of numbers and streams, using c strings in c++?

Im writing a census program that requires me to use c string objects to read in three things, names(states), population, and area. What I dont know and cant find in my text book, at least in a clear way, is how to read numbers and names from a text file saved separately in my directory. My objects are being declared as ifstream and ofstream.

How do i read in arrays of numbers and streams, using c strings in c++?
If you mean how to read them from the text file, ifstream and ofstream work just like any other stream, such as cin and cout:





ifstream read("census.txt")


string name


int population,area


read %26gt;%26gt; name


read %26gt;%26gt; population


read %26gt;%26gt; area


What is the function C++ to reserve the null terminated string that is passed in. library func use strlen()?

c++ doesnot have its own you have to implement it.


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

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

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





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


I am using C++ and I need help with a program question dealing with string/function call)?

Let's say I have a function defined as





str_call (int x)





When I do str_call(0), I want the function to return the string


"Ninety"...





How can I write up the function? I have no experience dealing with strings.

I am using C++ and I need help with a program question dealing with string/function call)?
See below for an example of a function that returns a string. The functionality you're looking for calls, I think, for a lookup table. The example also illustrates that.





By the nature of your question, I assume you're something of a beginner in C++. Some of the things you see below may be new to you, but it's never too soon to learn. C++ offers many useful features, and you should learn to take advantage of them.





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;map%26gt;





using namespace std;





typedef map%26lt;int,string%26gt; LookupTable;


typedef pair%26lt;int,string%26gt; LookupTableElement;





string translate(int,const LookupTable%26amp;);





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


LookupTable lookup;





// Initialize


lookup.insert(LookupTableElement(0,strin...


lookup.insert(LookupTableElement(1,strin...


// ...


lookup.insert(LookupTableElement(90,stri...





// Translate


cout %26lt;%26lt; translate(90,lookup) %26lt;%26lt; endl;


cout %26lt;%26lt; translate(99,lookup) %26lt;%26lt; endl;





return 0;


}





string translate(int x,const LookupTable%26amp; map) {


LookupTable::const_iterator i;


if ((i = map.find(x)) != map.end()) {


return i-%26gt;second;


} else {


return string("not found");


}


}





// Program output:


// ninety


// not found
Reply:I doubt you're dumb, you just haven't learned enough C++ yet. For now, you can skip over the more complicated stuff. The fundamentals of what you asked for - how to return a string from a function - are fairly simple, and clearly shown in my 'translate' function. Report It

Reply:When dealing with strings as output parameters of functions, it's best to provide the function a buffer for filling it up. For example:





bool str_call(int x, char *result, int resultSize)


{


if (x==0)


{


if (resultSize%26gt;=strlen("Ninety")) // check to see if the provided buffer is big enough


{


strcpy(result, "Ninety");


return true; // return a successfull return code


}


}





return false; // result isn't valid


}





void main()


{


char result[100] = { '\0' };





if (str_call(0, result, sizeof(result))==true) // Calling the str_call function


{


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


}


};





// Have fun,


// S. B.
Reply:You have two options. If you only ever want to return the one string, "ninety", then you can do this:





char *str_call(int x)


{


return "ninety";


}





my_other_function()


{


printf ("%s\n", str_call(0)); // Prints "ninety"


}








This is OK, but it's a bit limited. A better option would be to have something like this:








char *str_call(int x, char *storage)


{


strcpy(storage, "ninety");


return storage;


}





my_other_function()


{


char str[20];


printf ("str_call returns %s\n", str_call(0, str)); // Prints "str_call returns ninety"


printf ("Also, str = %s\n", str); // Prints "Also, str = ninety"


}








For completeness it's better to set limits on the size of these arrays, so you'd have this:





char *str_call(int x, char *storage, int maxlen)


{


strncpy(storage, "ninety", maxlen);


return storage;


}





my_other_function()


{


const int strSize = 20;


char str[strSize];


printf ("str_call returns %s\n", str_call(0, str, strSize)); // Prints "str_call returns ninety"


printf ("Also, str = %s\n", str); // Prints "Also, str = ninety"


}








Finally, if you're using C++ then you may as well also use the benefits of STL like this:





void str_call(int x, std::string %26amp;storage)


{


storage = "ninety";


}





my_other_function()


{


std::string str;


str_call(0, str);


printf ("str = %s\n", str); // Prints "str = ninety"


}
Reply:Have a read about pointers.





Strings are arrays of characters. when passing an array, you should pass a pointer the memory address of the first element in the array.





char mystring[50]





char* StringFunction(int x){


char mystring2[50];


strcpy(mystring2, "Ninety");


return mystring2;


}





int main(){


mystring = StringFunction(0);


cout %26lt;%26lt; mystring;


return 0;


}


__





I havnt been learning C++ long, but try compiling that. I can't garuntee it is the most efficient way even if it does work, but it might give you a start
Reply:go to www.freeprogrammersheaven.com and search you can learn and will get the answers

tarot cards

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

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





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





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

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





For the asker:


one of many variation to solve your problem would be:


1.) Read the file


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


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


4.) Tokenize the search result and format it


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














big_int_calc.cpp





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








*/





#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


#include"big_int.h"


#include"char_to_int.h"





int main(){


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


int option;


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


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


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


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


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





//big int to store result in


big_int result;


//big int to store input data


big_int in_data1, in_data2;





if(option == 1){


//variable to store the file name


char file_name[20];





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


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


//input of the file name


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





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


std::ifstream in;


in.open(file_name);





// outputs error if needed


if(!in){


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


};





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











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


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


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


while(!in.eof()){


char temp;


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





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





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





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


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


i = 0; // resets the index


};


//reads first number


if(second_num == false){


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


++i;


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


};





//reads in second number with filters


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


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


++i;


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


};


};


};





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


int result_option;


if(option == 1){


//calculates result


result = in_data1 + in_data2;


//ask user for the input of the option


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


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


result = in_data1 + in_data2;


if(result_option == 1){


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


result.output();


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


};





};





// outputs to file if option is 2


if(result_option == 2){


//calculates result


result = in_data1 + in_data2;


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


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


char outfile_name[20];


//declares the file to be written to


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


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





// format output


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


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


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


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


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


};





};


// output of ; at end of file


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











};


};





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


big_int entered_int;


if(option == 2){


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


int output_option;


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


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


char temp;


char int_in[500];





//inputs the big integer to the big_int class array


int index = 0;


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


//uses sential value to end input


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


if(temp == 'e'){


break;


};


//converts the char to integers


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


++index;


};


//inputs the value of n


entered_int.set_array_size(index);


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


int n;


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


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


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


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


};


// sets new array size


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


if(output_option == 1){


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


entered_int.output();


};





if(output_option == 2){


//writes to file if user chooses that optioin


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


char outfile_name[20];


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


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





//formats output with 50 char per line


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


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


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


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


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


};





};


//adds ; at end of file


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











};


};











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


int result_option;


if(option == 3){


//variable to store the file name


char file_name[20];





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


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


//input of the file name


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





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


std::ifstream in;


in.open(file_name);





// outputs error if needed


if(!in){


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


};





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











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


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


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


while(!in.eof()){


char temp;


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





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





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





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


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


i = 0; // resets the index


};


//reads first number


if(second_num == false){


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


++i;


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


};





//reads in second number with filters


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


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


++i;


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


};


};


};





//calculates result


result = in_data1 * in_data2;


//ask user for the input of the option


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


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


if(result_option == 1){


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


result.output();


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


};





};





// outputs to file if option is 2


if(result_option == 2){


//calculates result


result = in_data1 + in_data2;


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


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


char outfile_name[20];


//declares the file to be written to


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


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





// format output


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


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


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


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


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


};





};


// output of ; at end of file


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











};








/*


if(option == 4){


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


int fact_in;


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


big_int result;


result = fact(fact_in);


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


int result_option;


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


if(result_option == 1){


result.output();





};


// outputs to file if option is 2


if(result_option == 2){





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


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


char outfile_name[20];


//declares the file to be written to


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


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





// format output


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


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


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


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


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


};





};


// output of ; at end of file


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








};


};


*/





return 0;


};


How far from the end of the string should you place your finger to play the note C (523 Hz)?

A violin string is 28 cm long. It sounds the musical note A (440 Hz) when played without fingering.

How far from the end of the string should you place your finger to play the note C (523 Hz)?
There are two equations you'll need.





First, when you play a note on a string, the fundamental frequency causes a standing wave such that the length of the string equals 1/2 of a wavelength. So L = 1/2 wavelength.





Given the legnth of the string above (.28 m), you can figure out the wavelength.


.28 m = 1/2 wavelength


.56 m = wavelength





Second, velocity = frequency x wavelength.


Using the frequency given (440 Hz) and the wavelength just computed, you can find the velocity.





velocity = 440 Hz x .56 m = 246.4 m/s





This speed won't change even as you hold your finger on the string.





Starting with a velocity of 246.4 m/s and a desired frequency of 523 Hz, we can find the wavelength.





velocity = frequency x wavelength


246.4 m/s = 523 Hz x wavelength


.471 m = wavelength





Using this wavelength and the fact that the length of the string is 1/2 of a wavelength long, you get:





Length of string = 1/2 wavelength


Length of string = 1/2 (.471 m)


Length of string = .236 m





Since the question asks how far from the end you should place your finger, take the original string length and subtract the answer above.





distance from end = .28 m - .236 m = .044 m or 4.4 cm.


What's wrong with my C#.net code ,im trying to join a bunch of string and integers together.?

udate.Text = "Hello, " + DateTime.Now.DayOfWeek.ToString().Substr... 3) %26amp; " " %26amp; DateTime.Now.Day %26amp; ", " %26amp; definemonth() %26amp; " : You are not logged in.";


The error is at "Hello, " part it said ''Operator '%26amp;' cannot be applied to operands of type 'string' and 'string"

What's wrong with my C#.net code ,im trying to join a bunch of string and integers together.?
Concatenation in C# is done with + not %26amp;


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

My current code is:





SetDlgItemText (hwnd, QUESTIONBOX, EQ1)





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





Hmm wat if i use SetWindowText..


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

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


how to use "SetDlgItemText"





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





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





May be this can help you

secret garden

C program, use recursive method find string length?

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





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





int findlen(char * s) {


int len;


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


return 0;


}


len = findlen(s+1);


return len+1;


}





int main() {


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


int len = findlen(str);


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


}

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


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





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


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


if (!*s) {


return;


}


else{


*length++;


strlen(s++,length);


}


}





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


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

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

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


How do i make a program in c language that extracts the suffix of a word/string?

ex: String: Department


prefix: Depart


suffix: ment

How do i make a program in c language that extracts the suffix of a word/string?
try looking it on the web
Reply:Shouldn't you ask this in a different section? Most of us here know languages but not computer-programming.
Reply:I sincerely doubt that you'd be able to make a program which can truly capture the complexity of morphology. Just as internet translators are notoriously inadequate, a computer program would have to understand morphology like a human does, and so far I've seen very little evidence that this is possible.


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

The following program would do the trick.


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





int c=101;


int f()


{


c=c-1;


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


return 1;


}


void main()


{f();}





Hope this solves your problem.


-Regards, Rahul

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


FOR loop dude!


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





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


printf("Your string...");

pear

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

we can do this using the string functions





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


main()


{


char a[20],b[20];


printf("enter a string");


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


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


strrev(b);//reverses string b


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


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


else


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


return 0;


}

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

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


void main()


{


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


// now reverse the given string and store the


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


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


//palindrome else print that the string is not palindrome


}


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

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





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

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





char buf[32];


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





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





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


int yo = 12345;


char buf[30];


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





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





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


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


Getting input from a text file using c strings in c++?

How do i get input from a text file using c strings, not the standard string class. Is it possible?

Getting input from a text file using c strings in c++?
Sure, as long as you use the #include%26lt;fstream%26gt; header, and name the file you want to use as input. When you parse the data, just store it to a C-String, which as you should know is an array made exclusively of characters.


C program recursive method (find the character index in the string)?

str = "Hello world"


ch = "w"


use recursive method, no string.h function


return 'w' index = 6





int findIndexString(char str[ ], char ch)

C program recursive method (find the character index in the string)?
again, like before! I really hv too much time in my hands today :-p





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





int findIndexString(char str[], char ch) {


int pos;


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


return -1;


}


if(*str==ch) {


return 0;


}


pos = findIndexString(++str, ch);


if (pos%26lt;0) {


return pos;


} else {


return pos+1;


}


}


int main() {


char str[25]="hello world";


int pos = findIndexString(str, 'h');


printf("The position is %d\n", pos);


}
Reply:Hello,





I suppose this is just for fun? If so, ok.





Else please note It is particularly inefficient to use recursiveness for such low level functions. You put the system under heavy strain due to call stack adjustments needed to accomodate the numerous function calls (passing variables).
Reply:int findIndexString(char str[],char ch)


{


static int i=0;


if(*str =='\0')


return 0;


else if(*str == ch)


return i;


else{


i++;


return findIndexString(++str,ch);


}





}

nobile

I want to tokenize the string using the delimiter :some @.How to do this in C#.net?

Eg:suppose some string"My name@is xxx.@I am doing @so and so"


actually my intention is to store all these tokens in different variables.


let me say


x = My name


y = is xxx.


z =I am doing


a =so and so








Actally i know how to do it in java using the string tokezier.How to


do this in .Net.


Please help me.








Thanks in Advance..

I want to tokenize the string using the delimiter :some @.How to do this in C#.net?
string field = "My name@is xxx.@I am doing @so and so"


string[] result = field.Split(new char[]{'@'});


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

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





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





string s = "";





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





//now to search for a word use





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





Regards,


Need a short c++ program that counts how many words in a string?

cin%26gt;%26gt;"this is a test"


cout%26lt;%26lt; x %26lt;%26lt; "words in your string";





where x is determined to be 4 by some short function.

Need a short c++ program that counts how many words in a string?
the simplest one would be to count the no. of spaces in the string and report %26lt;%26lt;no_of_spaces+1 .


that's ofcourse the most basic program.. and it'll give u wong results more often than not.





ican post u the exact code.. (the perfect program) for this.. if u really need.. but it'll ofcourse take some time
Reply:Oh come on -- this is too easy to ask for help with. How far are you going to get asking someone else to do your homework for you?





Look, this is the basic pseudocode:





x = 0


while not (end of string) do {


if (current character is a blank space){


if (next character is not a blank){


x = x + 1


}


}


}


return x





that's basically it.


How do you tune a 6 string electric guitar to drop d tuning and drop c tuning?

either with an electric tuner or without i have an electric tuner i just dont know what to tune it to for drop c and drop d

How do you tune a 6 string electric guitar to drop d tuning and drop c tuning?
Dropped C tuning is an alternative guitar tuning style in which the lowest (sixth) string is tuned down two tones ("dropped") to C and the rest of the strings are tuned down one tone, thus making the overall tuning CGCFAD from low to high. Although popularly referred to as "Drop C", CGCFAD tuning is not in fact "Drop C" tuning; a "drop" tuning refers only to the dropping of the tuning of the lowest string; thus "Drop C" tuning is actually CADGBE and the tuning referred to is actually "Drop D, tuned down one whole step (tone)."[1] Throughout the rest of this article, what is referred to as drop C is CGCFAD, or drop D tuned down one whole step.





Dropped D tuning: DADGBE, also known as simply as drop D, is an alternate guitar tuning style in which the lowest (sixth) string is tuned down one whole step ("dropped") to D rather than E as in standard tuning (EADGBE or EADG).,

flower girl dresses