forked from rikardgn/learnCpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptrToCharVector.cpp
More file actions
41 lines (34 loc) · 861 Bytes
/
ptrToCharVector.cpp
File metadata and controls
41 lines (34 loc) · 861 Bytes
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
//Demonstates how to use a pointer and function to change a char arr/string to uppercase
//Rikard Grossman-Nielsen
//17th Jan 2023
#include <iostream>
using namespace std;
void charVecToUpper(char *ptrC);
int main(void){
int i;
char chrVector[]="hello";
cout << "Char vector before use of function:" << "\n";
i=0;
while(chrVector[i]!='\0'){
cout << chrVector[i];
i++;
}
cout << "\n";
charVecToUpper(&chrVector[0]);
//print each char of chrVector before and after upperCase converstion
cout << "Char vector after use of function:" << "\n";
i=0;
while(chrVector[i]!='\0'){
cout << chrVector[i];
i++;
}
cout << "\n";
return 0;
}
void charVecToUpper(char *ptrChr){
int i=0;
while(ptrChr[i]!='\0'){
*(ptrChr+i)=*(ptrChr+i)-32;
i++;
}
}