How to upper a specific char in a string with C

2 Answers

0 votes
#include <stdio.h>

void _charToUpper(char *p, int index) { 
    *(p + index) &= ~32; 
} 

int main(int argc, char **argv)
{ 
	char s[] = "abcdefgh"; 
	
	_charToUpper(s, 2); 
	_charToUpper(s, 3); 
	_charToUpper(s, 5); 
    
	printf("%s\n", s); 
	
	return 0; 
}   
 

/*
run:
 
abCDeFgh
 
*/

 



answered Jan 17, 2019 by avibootz
0 votes
#include <stdio.h>

void _charToUpper(char *p, int index) { 
    *(p + index) -= 32; 
} 

int main(int argc, char **argv)
{ 
	char s[] = "abcdefgh"; 
	
	_charToUpper(s, 2); 
	_charToUpper(s, 3); 
	_charToUpper(s, 5); 
    
	printf("%s\n", s); 
	
	return 0; 
}   
 

/*
run:
 
abCDeFgh
 
*/

 



answered Jan 17, 2019 by avibootz
...