Monday, May 24, 2010

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

In c++, what is the difference between a character array (or a pointer to one) and a literal string?

In c and in c++ a character array is an array of bytes, normally containing ASCII values. A literal string is an sequence of ASCII characters terminated with a null ('\0'). Example:





char array[9] = { 'a','b','c','d','e','f','g','h','i','j' };


char str[] = "abcdefghij";


char *ptr = "abcdefghij";





array[] will contain the ASCII string 'abcdefghij' without a null string terminator: example array[] contains:





[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]


a b c d e f g h i j





str[] contains:


[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]


a b c d e f g h i j '\0'





ptr will contain the address of the first byte of the literal string "abcdefghij"; ptr+10 will be the address of the null terminator.

In c++, what is the difference between a character array (or a pointer to one) and a literal string?
there is some difference in memory assignment and accesing if you put alignment larger than 1. Say compiler option alignment is 8, then compile will assign 8 byte space for one char. For string, it assignes memory space for each char either one byte (ANSI) or two bytes (unicode).





Therefore, accessing those char in array will be more complicated


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

then if he input a charecter how to promt him to enter integer again

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


isalph()


isalnum()


isdigit()


use them
Reply:all input is char values, they must be converted to int values, I believe 0 the character 0 is equal to 32, but you can say





if(x%26gt;='0' || x%26lt;'9') then


{


cout%26lt;%26lt;"This character is a number"


}





if you then wanted to convert it to a real number just subtract the character 0 from it IE '9' - '0' = 9


How to create a C program that will count the number of VOWELS and CONSONANTS in a inputted string?

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





void count(const char *str,


unsigned int *vowels,


unsigned int *constants) {


char *s = str;


*vowels = 0;


*constants = 0;





while (s) {


switch (tolower(*s)) {


case 'a':


case 'e':


case 'i':


case 'o':


case 'u':


(*vowels)++;


break;


default:


if (isalpha(*s))


(*constants)++;


}


s++;


}


}








Umm... Sorry, but can you explain what the most efficient way using library calls?

How to create a C program that will count the number of VOWELS and CONSONANTS in a inputted string?
2 ways to do this one is very basic and innefficient the other can be very complex but using existing library functions to do the work for ya





basic way is just a loop and compare one character at a time for any of the vowels





the other is to check out the string.h library


read the functions closely there is more than 1 way to do it


How do i write a c language program that gives the output as all possible combinations of a string input by?

user.

How do i write a c language program that gives the output as all possible combinations of a string input by?
As amazing as this may sound, this is something you can actually write in approximately 20 lines of code. You can use a FOR loop inside of a recursive function to do most of the work. Use the FOR loop to break down a string into smaller sub-sections for each recursion. This example will hopefully give you an idea of what happens.





eg.





[abcd]





├ [a] - [bcd]





├┬ [ab] - [cd]


││


│├┬ [abc] - [d]


│││


││└─ [abcd] - [ ]


││


│└┬ [abd] - [c]


│   │


│   └─ [abdc] - [ ]





├ [b] - [acd]








Pay close attention to these two lines.





├ [a] - [bcd]





├┬ [ab] - [cd]





In the second string, [bcd], the first character, [b], is appended to the first string, [a]. In the next step,





├┬ [ab] - [cd]


││


│├┬ [abc] - [d]








the same thing occurs. In the last step,





│├┬ [abc] - [d]


│││


││└─ [abcd] - [ ]





the same thing occurs. However, this time the second string has no characters to add to the first string, so you would add the first string to an array or output it. In the next step,





├┬ [ab] - [cd]


││


│├┬


│││


││└─


││


│└┬ [abd] - [c]








you'll notice the second character of the second string is appended to the first string. This is where you want to use a FOR loop to cycle through the string. I'll leave it up to you on how to actually implement this. If you need any more help or are confused, send me an email.
Reply:could u explain your problem statement better...

cheap flowers