Skip to content

Commit db94823

Browse files
authored
Create accept-array-of-char.cpp
1 parent 6c84a8d commit db94823

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

accept-array-of-char.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// C++ program to demonstrate how to accept a string from a user using character array
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
int main()
7+
{
8+
char str[15]; int i = -1;
9+
10+
do {
11+
i++;
12+
str[i] = getchar();
13+
} while (str[i] != '\n' && i<14);
14+
15+
int length = i;
16+
for (int j = 0; j < length; j++) {
17+
cout << str[j];
18+
}
19+
return 0;
20+
}

0 commit comments

Comments
 (0)