| | |
Reversive Array/Integer
| View Poll Results: what is the appropriate coding? | |||
| 1 | | 0 | 0% |
| 2 | | 1 | 100.00% |
| 3 | | 0 | 0% |
| 4 | | 0 | 0% |
| Voters: 1. You may not vote on this poll | |||
![]() |
•
•
Join Date: Jul 2004
Posts: 2
Reputation:
Solved Threads: 0
How can i write the coding for a reversive of a given integers.
for example:
char str[] = "012345";
Reverse( str );
printf( str );
then the output will be displayed as "543210"
i need pointer as well to null-terminate string as a parameter and reverses this string. then, the string remains null terminated.
void reverse(char *s)
please help.this is very urgent. thanks.
for example:
char str[] = "012345";
Reverse( str );
printf( str );
then the output will be displayed as "543210"
i need pointer as well to null-terminate string as a parameter and reverses this string. then, the string remains null terminated.
void reverse(char *s)
please help.this is very urgent. thanks.
_strrev, _wcsrev, _mbsrev
Reverse characters of a string.
char *_strrev( char *string );
wchar_t *_wcsrev( wchar_t *string );
unsigned char *_mbsrev( unsigned char *string );
Routine Required Header Compatibility
_strrev <string.h> Win 95, Win NT
_wcsrev <string.h> or <wchar.h> Win 95, Win NT
_mbsrev <mbstring.h> Win 95, Win NT
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns a pointer to the altered string. No return value is reserved to indicate an error.
Parameter
string
Null-terminated string to reverse
Remarks
The _strrev function reverses the order of the characters in string. The terminating null character remains in place. _wcsrev and _mbsrev are wide-character and multibyte-character versions of _strrev. The arguments and return value of _wcsrev are wide-character strings; those of _mbsrev are multibyte-character strings. For _mbsrev, the order of bytes in each multibyte character in string is not changed. These three functions behave identically otherwise.
Security Note These functions incur a potential threat brought about by a buffer overrun problem. Buffer overrun problems are a frequent method of system attack, resulting in an unwarranted elevation of privilege. For more information, see Avoiding Buffer Overruns.
Generic-Text Routine Mappings
if u want something else .. i will attach masteringstring.cpp ...
Reverse characters of a string.
char *_strrev( char *string );
wchar_t *_wcsrev( wchar_t *string );
unsigned char *_mbsrev( unsigned char *string );
Routine Required Header Compatibility
_strrev <string.h> Win 95, Win NT
_wcsrev <string.h> or <wchar.h> Win 95, Win NT
_mbsrev <mbstring.h> Win 95, Win NT
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns a pointer to the altered string. No return value is reserved to indicate an error.
Parameter
string
Null-terminated string to reverse
Remarks
The _strrev function reverses the order of the characters in string. The terminating null character remains in place. _wcsrev and _mbsrev are wide-character and multibyte-character versions of _strrev. The arguments and return value of _wcsrev are wide-character strings; those of _mbsrev are multibyte-character strings. For _mbsrev, the order of bytes in each multibyte character in string is not changed. These three functions behave identically otherwise.
Security Note These functions incur a potential threat brought about by a buffer overrun problem. Buffer overrun problems are a frequent method of system attack, resulting in an unwarranted elevation of privilege. For more information, see Avoiding Buffer Overruns.
Generic-Text Routine Mappings
C Syntax (Toggle Plain Text)
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined _tcsrev _strrev _mbsrev _wcsrev Example /* STRREV.C: This program checks an input string to * see whether it is a palindrome: that is, whether * it reads the same forward and backward. */ #include <string.h> #include <stdio.h> void main( void ) { char string[100]; int result; printf( "Input a string and I will tell you if it is a palindrome:\n" ); gets( string ); /* Reverse string and compare (ignore case): */ result = _stricmp( string, _strrev( _strdup( string ) ) ); if( result == 0 ) printf( "The string \"%s\" is a palindrome\n\n", string ); else printf( "The string \"%s\" is not a palindrome\n\n", string ); } Output Input a string and I will tell you if it is a palindrome: Able was I ere I saw Elba The string "Able was I ere I saw Elba" is a palindrome
Real Eyes Realize Real Lies
My Resume
My Resume
Obfuscated for the sake of being too homework-sounding with no work presented.
#include <stdio.h> char *f(char*s){char*t=s,*u=t;while(*u)++u;--u; while(t<u){char x=*t;*t++=*u;*u--=x;}return s;} int main ( void ) { char text[] = "The quick brown fox"; puts ( text ); puts ( f ( text ) ); return 0; } /* my output The quick brown fox xof nworb kciuq ehT */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
•
•
Originally Posted by vistatic
Actually i was asking about integers, not string char. by given integers 012345, how can i actually reverse it? .....
•
•
•
•
Originally Posted by vistatic
i need pointer as well to null-terminate string as a parameter and reverses this string. then, the string remains null terminated.
char str[] = "012345";
C Syntax (Toggle Plain Text)
char text[] = "012345"; /* "The quick brown fox"; */
But no one is here to do your homework. What coding attempt have you posted? Or do you expect to post homework questions and simply get a correct answer, nicely formatted and commented?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
•
•
Originally Posted by vistatic
Actually i was asking about integers, not string char. by given integers 012345, how can i actually reverse it? .....
see this example
Summary
An algorithm that reverses the order of elements in a sequence
Synopsis
C Syntax (Toggle Plain Text)
#include <algorithm> namespace std { template <class BidirectionalIterator> void reverse(BidirectionalIterator start, BidirectionalIterator finish); }
The algorithm reverse() reverses the elements in a sequence so that the last element becomes the new first element, and the first element becomes the new last. For each non-negative integer i <= (finish - start)/2, reverse() applies iter_swap() to all pairs of iterators start + I, (finish - I) - 1.
Complexity
reverse() performs exactly (finish - start)/2 swaps.
Example
C Syntax (Toggle Plain Text)
// // reverse.cpp // #include <algorithm> // for reverse, reverse_copy #include <vector> // for vector #include <iostream> // for cout, endl #include <iterator> // for ostream_iterator int main () { typedef std::vector<int, std::allocator<int> > Vector; typedef std::ostream_iterator<int, char, std::char_traits<char> > Iter; // Initialize a vector with an array of integers. const Vector::value_type a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; Vector v (a + 0, a + sizeof a / sizeof *a); // Print out elements in original (sorted) order. std::cout << "Elements before reverse: \n "; std::copy (v.begin (), v.end (), Iter (std::cout, " ")); // Reverse the ordering. std::reverse (v.begin (), v.end ()); // Print out the reversed elements. std::cout << "\n\nElements after reverse: \n "; std::copy (v.begin (), v.end (), Iter (std::cout, " ")); std::cout << "\n\nA reverse_copy to cout: \n "; std::reverse_copy (v.begin (), v.end (), Iter (std::cout, " ")); std::cout << std::endl; return 0; } Program Output: Elements before reverse: 1 2 3 4 5 6 7 8 9 10 Elements after reverse: 10 9 8 7 6 5 4 3 2 1 A reverse_copy to cout: 1 2 3 4 5 6 7 8 9 10
Real Eyes Realize Real Lies
My Resume
My Resume
![]() |
Similar Threads
- How to get an integer value of byte array? (Java)
- did I used Array??? (C++)
- using boolean expression on an array (Java)
- Return multidimension array (C)
Other Threads in the C Forum
- Previous Thread: recursive algorithm
- Next Thread: help me wth file
| Thread Tools | Search this Thread |
* adobe ansi api array binarysearch centimeter changingto char character cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax database directory feet fflush fgets file floatingpointvalidation fork frequency function givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux highest histogram homework i/o inches infiniteloop input interest intmain() iso keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate looping lowest match meter microsoft mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc program programming pyramidusingturboccodes read recv recvblocked repetition reversing scanf scheduling segmentationfault send single socketprograming socketprogramming stack standard string suggestions systemcall unix urboc user voidmain() wab whythiscodecausesegmentationfault win32api windows.h windowsapi






