Theory
Write a C program to search all occurrences of a character in a string.
Without using pointer:
/**
* C program to compare two string without using string library functions
*/
#include
#define MAX_SIZE 100 // Maximum string size
/* Compare function declaration */
int compare(char * str1, char * str2);
int main()
{
char str1[MAX_SIZE], str2[MAX_SIZE];
int res;
/* Input two strings from user */
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
/* Call the compare function to compare strings */
res = compare(str1, str2);
if(res == 0)
{
printf("Both strings are equal.");
}
else if(res < 0)
{
printf("First string is lexicographically smaller than second.");
}
else
{
printf("First string is lexicographically greater than second.");
}
return 0;
}
/**
* Compares two strings lexicographically.
* Returns 0 if both strings are equal,
* negative if f.... Show MoreFrom Strings in C programming · C programming
Write a C program to search all occurrences of a character in a string.
Write a C program to find total number of vowels and consonants in a string.
Write a C program to concatenate two strings.
Write a C program to find maximum occurring character in a string.
Write a C program to count occurrences of a word in a given string.
Write a C program to copy one string to another string.
Write a program in C to find the largest and smallest word in a string.
Write a C program to find length of a string.