/* To reverse the given string using pointer By $ */
#include <stdio.h>
#include <string.h>
void main ()
{
char str[15];
char rev[15];
int i;
int count;
char* p;
gets(str);
count = strlen(str);
p = rev + strlen(str)-1;
for(i = 0; i < count; i++)
{
*(p - i) = *(str + i);
}
rev[count]='\0';//in some compilers it may show error show u can make it NULL
/* verify results */
printf("Original string: %s\n",str);
printf("Reversed string: %s\n",rev);
}
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
int num,i,j,result,index;
char name[25][25],temp[25];
clrscr();
printf("\nNumber of names to be sorted in descending order\n");
scanf("%d",&num);
printf("Enter %d names to be sorted\n",num);
for(i=0;i<num;i++)
scanf("%s",name[i]);
for(i=0;i<num;i++)
{ index=i;
for(j=i+1;j<num;j++)
{
result=strcmp(name[index],name[j]);
if(result<0)
index=j;
}
strcpy(temp,name[index]);
strcpy(name[index],name[i]);
strcpy(name[i],temp);
}
printf("\nNames Sorted in Descending Order\n");
for(i=0;i<num;i++)
{
printf("\t%s",name[i]);
}
}
email ThisBlogThis!Share to TwitterShare to Facebook
reverse (char *p) { char c, *p1, *p2;
if (strlen(p) <= 1) return; for (p1=p, p2=p+strlen(p)-1; p1<p2; c=*p1, *p1=*p2, *p2=c, p1++, p2--); }
reverce input show
The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.
To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include<string> using std::string; string reverse (const string& s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout << "Enter a number: "; string s {}; std::cin >> s; std::cout << "The number in reverse is: " << reverse (s); }
a string constant
wefwfe
Assume C#, not C: Traditional way: public string Reverse(string s) { if (string.IsNullOrEmpty(s)) return s; // "" or null char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } or as an extension method: public static string Reverse(this string s) { if (s == "") return ""; char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } The differences of the 2 methods above is on the caller (how to use Reverse()), and they may co-exist: For example: string test = "abc"; string result1 = Reverse(test); // traditional way string result2 = test.Reverse(); // call the extension
The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.
To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include<string> using std::string; string reverse (const string& s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout << "Enter a number: "; string s {}; std::cin >> s; std::cout << "The number in reverse is: " << reverse (s); }
a string constant
wefwfe
Assume C#, not C: Traditional way: public string Reverse(string s) { if (string.IsNullOrEmpty(s)) return s; // "" or null char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } or as an extension method: public static string Reverse(this string s) { if (s == "") return ""; char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } The differences of the 2 methods above is on the caller (how to use Reverse()), and they may co-exist: For example: string test = "abc"; string result1 = Reverse(test); // traditional way string result2 = test.Reverse(); // call the extension
special character in c language are as follows~ ' ! @ # % ^ & * () _ - + = | \ {} [] : ; " <> , . ? /
its just like a string of c++
#include #include #include int reverse(int i);char st[]="ven123kat";void main() {printf("\nThe string is: %s", st);reverse(0);printf("\nReversed string is: %s", st);getch();}int reverse(int i) {if (i
I'd use sprintf (assuming the number wasn't a string already) and pointers. If that's not enough of a clue, you're really not ready to be in this programming class.
Use the atoi() or atol() function.
console.wrikerle("""");
int a; -- variable definition"int a" -- string literal