main() { char a[100],b[100]; strcpy(a, "hello"); rev_str(a,b); printf("%s", b); // this prints "olleh" }
int main(int argc, char *argv[]) { char * str; str = malloc(sizeof(40000)); rev_str(str); printf("%s", str); return 0; }
char *multiply(char *num1, char *num2) { if (!num1 || !num2) return(0); int l1, l2, i, j, t, c, max; char *num1_r, *num2_r, *res_r; if (!(l1 = strlen(num1)) || !(l2 = strlen(num2))) return(0); num1_r = rev_str(num1, l1); num2_r = rev_str(num2, l2); res_r = calloc(l1 + l2, sizeof(char)); c = 0; max = 0; for (i = 0; i < l1; i++) { for (j = 0; j < l2; j++) { t = (num1_r[i] - '0') * (num2_r[j] - '0'); t += c; res_r[i + j] += t; c = res_r[i + j] / 10; res_r[i + j] %= 10; } if (c) { max = i + j; res_r[max] += c; c = 0; } else { max = i + j - 1; } } free(num1_r); free(num2_r); num1_r = calloc(max + 2, sizeof(char)); i = max; j = 0; while (i >= 0) num1_r[j++] = res_r[i--] + '0'; free(res_r); if (num1_r[0] == '0') num1_r[1] = 0; return(num1_r); }
void rev_str(char* s) { if(*s != '\0') rev_str(s+1); printf("%c",*s); }
main() { char str1[100],str2[100]; int d,i,j; clrscr(); printf( "Enter a string \n " ); scanf( "%[^\n]",str1); for(d=0;str1[d]!='\0';d++); rev_str(str1,d); getch(); }
void *rev_str(char *a,char *b) { if(*a=='\0'){ *b='\0'; return; } *b=*(a+strlen(a)-1); *(a+strlen(a)-1)='\0'; rev_str(a,b+1); }
int main(int argc, const char * argv[]) { rev_str("born2c0de"); return 0; //test code /* MyClass Obj; Obj.x = 10; Obj.y = 20; char *p; p = (char*) malloc(sizeof(char)+ 1); sprintf(p, "%d", Obj.add()); sprintf((p+2), "%d", Obj.add() + 9); std::cout << p; std::cout << *(p + 2); free(p); */ //Stack code /* Stack myStack; myStack.push(100); myStack.push(200); myStack.push(400); myStack.push(500); std::cout << myStack.pop(); std::cout << myStack.pop(); std::cout << myStack.pop(); std::cout << myStack.pop(); std::cout << myStack.pop(); //Queue code Queue myQueue; myQueue.add(100); myQueue.add(200); myQueue.add(300); myQueue.add(400); myQueue.del(); myQueue.del(); myQueue.del(); myQueue.add(500); myQueue.add(600); myQueue.display(); /*myQueue.del(); myQueue.del(); myQueue.del(); myQueue.del(); myQueue.del(); myQueue.del(); myQueue.display(); */ return 0; }
static void my_itoa(int nb, char *str) { int i; if (nb < 0) nb *= -1; i = 0; while ((nb / 10) > 0) { str[i] = (nb % 10) + '0'; nb = nb / 10; ++i; } str[i] = (nb % 10) + '0'; ++i; str[i] = '\0'; rev_str(str); }