📝 Added sandbox (code sketchbook)
This commit is contained in:
parent
b475595f7f
commit
b5daf18b1a
142 changed files with 100702 additions and 0 deletions
30
sandbox/reverse_string2.c
Normal file
30
sandbox/reverse_string2.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* https://www.w3schools.in/c-programming/examples/reverse-a-string-in-c */
|
||||
#include <stdio.h>
|
||||
|
||||
void revAString(char strg[]) {
|
||||
int g, numb;
|
||||
int tmpry = 0;
|
||||
|
||||
// grabs the length of the given string
|
||||
for(numb = 0; strg[numb] != 0; numb++);
|
||||
printf("numb(string length) = %d\n", numb);
|
||||
for(g = 0; g < numb / 2; g++) {
|
||||
tmpry = strg[g];
|
||||
printf("tmpry = %c\n", tmpry);
|
||||
strg[g] = strg[numb - 1 - g];
|
||||
printf("strg[g] = %c\n", strg[g]);
|
||||
strg[numb - 1 - g] = tmpry;
|
||||
printf("strg[numb - 1 - g] = %c\n", strg[numb - 1 - g]);
|
||||
}
|
||||
for (g = 0; g < numb; g++)
|
||||
putchar(strg[g]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char strg[60];
|
||||
printf("Please insert the string you wish to get reversed: ");
|
||||
scanf("%s", strg);
|
||||
revAString(strg);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue