-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50bc7a8
commit 0c9855a
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Name: Adithya A | ||
Roll No: 03 | ||
Class : CS2B | ||
*/ | ||
//Input any string from the user and find the first occurrence of a given character in the string. | ||
#include <stdio.h> | ||
#include <string.h> | ||
int first_occurance(char str[1000],char c){ | ||
int i = 0; | ||
for(i=0;i<strlen(str);i++){ | ||
if(c==str[i]){ | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
void main(){ | ||
char str[50], c; | ||
printf("Enter the string :\n"); | ||
scanf("%s", str); | ||
printf("Enter character to be searched for :\n"); | ||
scanf("%c", &c); | ||
int index = first_occurance(str,c); | ||
if(index==-1){ | ||
printf("Character Not Found"); | ||
} | ||
else{ | ||
printf("character position is at %d \n", index+1); | ||
printf("character index is at %d \n", index); | ||
} | ||
} |
Binary file not shown.