forked from Tomkndn/C
-
Notifications
You must be signed in to change notification settings - Fork 2
/
string.c
54 lines (47 loc) · 1.1 KB
/
string.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<stdio.h>
void prinfun(char arr[]);
int length(char arr[]);
int main(){
char str[100];
char ch;
int i = 0;
printf("Input Your String: ");
while (ch != '\n')
{
scanf("%c", &ch);
str[i] = ch;
i++;
}
str[i] = '\0';
puts(str);
char shortName[50];
char fullName[100];
printf("Enter your full name: ");
fgets(fullName, 100, stdin);
// printf("Your Full Name is: ");
puts(fullName);
printf("Enter your short name: ");
scanf("%s", shortName);
printf("Your Short name is: ");
prinfun(shortName);
printf("Your Length of Full Name is(with space): %d ",length(fullName));
printf("\nYour Length of Full Name is: %d ",length(shortName));
printf("\nYour Length of String is(with space): %d ",length(str));
// printf("HELLO!!!");
return 0;
}
void prinfun(char arr[]){
for (int i = 0; arr[i] != '\0'; i++)
{
printf("%c",arr[i]);
}
printf("\n");
}
int length(char arr[]){
int count = 0;
for (int i = 0; arr[i] != '\0'; i++)
{
count++;
}
return count-1;
}