Arrays And Strings in 'C'
Arrays and Strings in C |
Strings can be represented as a one-dimensional character-type array. Each character within the string will be stored within one element of the array.
Most C compilers include library functions that allow strings to be compared, copied or concatenated.
The following program makes use of the library functions strcmp() (to compare two strings, it does not distinguish between upper & lowercase) and strcpy() (to copy one string to another).
Program -1
#include<stdlib.h>
/* Sort A List Of Words. Using A Two-Dimensional Character Array */
{ int element, n=0;
char word[10][12];
void sort(int n,char word[][12]);
printf("Enter One Word Per Line\n");
printf("Type \'END\'when finished\n\n");
while(strcmp(word[n++], "END"));
sort(--n,word);
printf("\nSorted List of Words :\n");
for(element=0; element<n; ++element)
printf("\nWord[%d] : %s", element+1, word[element]);
}
void sort(int n, char word [][12])
{ char temp[12]
int element, item;
for(item=0; item<n-1 ; ++item
for(element=item+1; element<n; ++element)
if(strcmp(word[item], word[element]) > 0 )
{ strcpy(temp, word[item]);
strcpy(word[item]), word[element]);
strcpy(word[element], temp);
}
return
}
Read Also:
Exercise regularly. Eat a nutritious diet. Don't smoke - WHO (Covid-19).
- Learn how to write the C program step-by-step | Lesson -1
- Learn how to write the C program step-by-step | Lesson -2
- Learn how to write the C program step-by-step | Lesson -3
- Learn how to write the C program step-by-step | Lesson -4
- Learn how to write the C program step-by-step | Lesson -5
- Learn how to write the C program step-by-step | Lesson -6
- Learn how to write the C program step-by-step | Lesson -7
Let's see also...
- Revolution in Information Technology
- Important Terminology of Computer Science
- Most useful website list for job seekers
- Do you know how to delete Facebook account
- What is TCP/IP Reference Model
No comments:
For More Details Subscribe & Comment..!