Write a function upper() that accepts a string and converts all its characters into uppercase characters
as example upper("c programming")=C PROGRAMMING
as example upper("c programming")=C PROGRAMMING
This file contains hidden or 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
#include <stdio.h> | |
#include <string.h> | |
#include <stdbool.h> | |
bool is_upper(char x) | |
{ | |
if((int)x>=65&&(int)x<=90) | |
{ | |
return true; | |
} | |
return false; | |
} | |
char *upper(char *base)//passing array to a function that returns a pointer to char | |
{ | |
while(*base!='\0') | |
{ | |
if(is_upper(*base)||*base==' '){*base++;} | |
else{*base-=32;base++;} | |
} | |
return base; | |
} | |
int main() | |
{ | |
char array[20]="hE l lO"; | |
upper(array); | |
puts(array); | |
return 0; | |
} |
No comments:
Post a Comment