Monday, May 24, 2010

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

Firstly its cin%26gt;%26gt;


u'll also need the command getline()


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

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





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

edible flowers

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

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





Assuming,


string searchString = "abcbdefb";


char charToFind = 'b';





Regular Expressions:


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





IndexOf:


int numberOfChars = 0;


int lastIndex = 0;


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


{


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


if (lastIndex == -1) break;


numberOfChars++;


}

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


Comparing 2 strings in C?

Here is the problem. I need to compare two strings in C language.





What i have is a program reading in data from a file. i read in information in the form fscanf(file,"%s",%26amp;last);


if(d.filed==last)


{ execute whats in here)


else if(d.filed==first)


{execute here}





Note that in the struct defined as struct test, lets say d.filed was " Mike". when i read in from the file, for some reason last does not receive the value "Mike" because i try to print and i receive some weird character. i defined last as being ** Char last,first;

Comparing 2 strings in C?
It's nice to have the whole program so we know how much to explain. For example, fscanf will read in characters until it reaches a whitespace character or NULL, then writes a null into the target string. If d.filed has any whitespace characters in it, the strings won't be equal.





Second, for manipulating strings you want the string.h (usually) or ctype.h (occasionally) header files. In this case you want the function int strcmp(char *, char*) from string.h. It returns 0 if the two strings are equal.





I would write it as if (!strcmp((d.filed), last){


.


.


.


}


else


{


.


.


.


}


but since I don't have the programs I don't know whether you need the second test.





A word about my sources: C++ has been described by its creator as C with classes and namespaces. cplusplus.com is an excellent site for documentation of both C and C++, however it obviously focuses on the latter. When they incorporated the standard template library into C++ they renamed all the standard c headers, so stdio.h became cstdio, stdlib.h became cstlib and of course string.h became cstring. In C++. In C they remain what they always were. Or as my GCC cstring header says:





/** @file cstring


* This is a Standard C++ Library file. You should @c #include this file


* in your programs, rather than any of the "*.h" implementation files.


*


* This is the C++ version of the Standard C Library header @c string.h,


* and its contents are (mostly) the same as that header, but are all


* contained in the namespace @c std (except for names which are defined


* as macros in C).


*/





C doesn't have namespaces. Thus you can learn what you need about C functions at C++, but you have to look elsewhere than you would in a C programming site. That's why I'm going to list the links to the page where I got some information after it.
Reply:use strcmp().





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





int strcmp(const char *s1, const char *s2);


Is there c# program to convert 4 digit no to 4 thousand 6 hundred 3 ten 2 unit manner without using any string

how to convert 4 digit number to the following example?


Example. 4632 want to convert 4 thousand 6 hundred 3 ten 2 unit

Is there c# program to convert 4 digit no to 4 thousand 6 hundred 3 ten 2 unit manner without using any string
#include%26lt;stdio.h%26gt;


void main()


{


int num,n1,n2,n3,n4;


printf("\nEnter 4 digit number");


scanf("%d",num); //ex4632





n1 = num/1000; //n1=4


n2 = (num/100)%10 //n2=6


n3 = (num/10)%10 // n3=3


n4 = num % 10 // n4 = 2





printf("\n %d = %d thousand %d hundred %d ten $d unit",num,n1,n2,n3,n4);


}





This is the only sensible solution dude.
Reply:Without using string it is not possible. otherwise the question is incomplete try to explain it with more details.
Reply:Without using a string? Ouch. How would you store the literal string "thousand" without using a string? You'd probably have to output it one character at a time, 't', 'h', 'o', 'u'....





In fact, the "string" type was created specifically so you didn't have to do that sort of silly char-at-a-time stuff. Why are you trying to do it the hard way? A sadistic professor? :)


Can anybody help me in coding in c to arrange the words in ascending order of word length given in a string?

Quicksort

Can anybody help me in coding in c to arrange the words in ascending order of word length given in a string?
find the length of the string using strlen and sort the words using any sorting technique(Bubble sort)
Reply:Yes just sort it.

covent garden

Saturday, May 22, 2010

Write a program in C# to sort the student list based on their names. The list is stored in a string array.?

Array.Sort( studentArray );





Anything else?

Write a program in C# to sort the student list based on their names. The list is stored in a string array.?
do your own homework.


Strings in c program?

what is the full defination of strings in c programing

Strings in c program?
A string in C is actually a character array. There are several methods of declaring the variable.


This first example declares a variable that can hold 4 characters. Below it is the initialized version


of the same declaration. The 5th space is for the end of string character that is automatically


added to the end of all strings:


char var[5];


char var[5] = "abcd";


char var[] = "abcd"; /* Equivalent to above. */


This type of declaration precludes the subsequent use of the assignment operator to


change the value stored in var. However, the value may be changed by using functions


such as strcpy(), fscanf(), and fgets().


Another declaration method is to declare a pointer variable. Notice in the first example a


size has not be determined. The assignment operator may be used to initialize the array


later but functions may not be used for initialization. Once initialized, the maximum size


of the array has been set as far as functions are concerned and functions may be used to


change the value. I think the assignment operator may be used to subsequently assign


longer strings to the pointer but I am not sure yet. The second example shows


initialization during declaration. p345


char *var;


char *var = "abcd";
Reply:An array of 8-bit characters, typically with a zero null terminator.





char myArray[] = "abcd";


is 5 characters ... the fifth is the null terminator.

email cards