C Program to find first occurrence of character in string

list of programs below: C Program to find first occurrence of character in string using functions, C Program to find first occurrence of character in string using arrays,C Program to find first occurrence of character in string using pointers

C Program to find first occurrence of character in string using functions arrays pointers
C Program to find first occurrence of character in string using functions arrays pointers

Input a  string and character. Starting from first character in string
to last character of string, seach for occurrence of input character and increment count variable when character not found. if character is found, output count which is position of character.

write a C Program to find first occurrence of character in string using arrays using functions

write a C Program to find first occurrence of character in string using arrays write logic in function

#include<stdio.h>
main()
{
char str[30];
char c
printf(“…Finding first occurrence of a character in a string….”)
printf(“\n enter the string \n”);
gets(str);
printf(“\n enter the character \n”);
gets(c);
printf( “\n First occurrence of character is at position no. %d”, find(str,c));
}

// function to find position if character in string
int find( const char list[], char what )
{
int i, count=0 ;
for(i=0; list[i] != 0 ; ++i )
++count ;
return count ;
}

OUTPUT:

…Finding first occurrence of a character in a string….

enter the string

programmingsimplysolved

enter the character

g

First occurrence of character is at position no. 4

write a C Program to find first occurrence of character in string using pointers

write a C Program to find first occurrence of character in string using pointers

#include<stdio.h>
main()
{
string *str;
char c
printf(“…Finding first occurrence of a character in a string…\n.”);
printf(“enter the string\n”);
gets(str);
printf(“\n enter the character \n”);
gets(c);
First_occurrence(str,  c)
}

void First_occurrence(string str, char c)
{
int count=1;
while (*str=’\0′)
{
if if (strCmp(*str,c )!=0)
{
printf( ” \n  First occurrence of character is at position no. %d”, count)
exit(0);
}
*str++;
count++;
}
printf( “\n The character does not exist in string”)
}

OUTPUT:

…Finding first occurrence of a character in a string….

enter the string

programmingsimplysolved

enter the character

m

First occurrence of occurrence is at position no.7

write a C Program to find first occurrence of character in string using arrays

write a C Program to find first occurrence of character in string using arrays

#include<stdio.h>
main()
{
char str[30];
char c
printf(“…Finding first occurrence of a character in a string….”);
printf(“\n enter the string \n”);
gets(str);
printf(“\n enter the character \n “);
gets(c);
int i=0;
while str[i]!=’\0′)
{
if (strCmp(str[i],c )!=0)
{
printf( “\n First occurrence of character is at position no. %d”, i+1)
exit(0);
}
i++
}
printf( “\n The character does not exist in string”)
}

OUTPUT:

…Finding first occurrence of a character in a string….

enter the string

programmingsimplysolved

enter the character

g

First occurrence of character is at position no .4

write a C Program to find first occurrence of character in string using pointers

write a C Program to find first occurrence of character in string using pointers

#include<stdio.h>
main()
{
string *str;
char c
printf(“…Finding first occurrence of a character in a string…\n.”);
printf(“enter the string\n”);
gets(str);
printf(“\n enter the character \n”);
gets(c);
int count=1;
while (*str=’\0′)
{
if if (strCmp(*str,c )!=0)
{
printf( ” \n  First occurrence of character is at position no. %d”, count)
exit(0);
}
*str++;
count++;
}
printf( “\n The character does not exist in string”)
}

OUTPUT:

…Finding first occurrence of a character in a string….

enter the string

programmingsimplysolved

enter the character

r

First occurance of occurrence is at position no. 5

Other programs:

Static variable scope
Register variable scope
External variable scope
Automatic variable scope
amicable number
Prime number
Perfect number
Palindrome number
Strong number
Find Factorial 
Biggest Number
Average of n numbers
convert decimal number to octal
decimal number to hexadecimal
decimal number to binary
simple interest
compound interest
Add sparce matrices
Add matrices
 file copying
Palindrome string
Reverse string
String length
Replace characters in string
substring or not using arrays
First occurrence of character in string
Last occurrence of character in string
Convert to uppercase
Convert to lowercase
Concatenate strings 
Compare strings
Generate Employee payslips
Count students scoring marks>50%
convert weight into grams

 

Leave a Reply

Your email address will not be published. Required fields are marked *