Segment Violation
1
Name:
fsdf
2011-03-14 20:32
I cant find the last segment violation, I think its in line 26 but I dont know what it should be.
#include "stdio.h"
#include "string.h"
// function prototypes
void strrvr( char outstr[] , char instr[] );
// driver
int main()
{
char outstr[100];
char instr[100]="emordnilap";
strrvr(outstr, instr);
printf( "%s\n", outstr );
return( 0 );
}
// strrvr function
void strrvr(char strout[], char strin[])
{
int i;
int n = strlen( strin );
strout[i] = strout[n]; // copy the null string terminator
for (i = 0 ; i < n ; i-- )
strout[n-i-1] = strin[n];
}
2
Name:
Anonymous
2011-03-14 20:37
I lol'd.
3
Name:
Anonymous
2011-03-14 20:42
this code isnt even mine, just trying to help out a friend
4
Name:
Anonymous
2011-03-14 20:46
Change
for (i = 0 ; i < n ; i-- )
strout[n-i-1] = strin[n];
to
for (i = 0 ; i < n ; i++)
strout[i] = strin[i];
You're welcome now fuck off.
5
Name:
Anonymous
2011-03-14 20:48
>>4
Storing the data in the correct variables left as an exercise to the autists.
6
Name:
Anonymous
2011-03-14 20:50
>>1-5
seg̕me͡n̛tat҉io҉ņ ͢f̸ault҉
7
Name:
Anonymous
2011-03-14 20:56
[code] // copy the null string terminator[/spoiler]
Don't you just love it when the comments are incorrect
8
Name:
Anonymous
2011-03-14 20:57
>>7
code/spoiler? What the hell was I thinking?
9
Name:
Anonymous
2011-03-14 21:12
sill wont reverse the string to palindrome
10
Name:
Anonymous
2011-03-14 21:19
>>9
Can you
really not see why that is, or are you pulling my leg?
11
Name:
Anonymous
2011-03-14 21:19
12
Name:
Anonymous
2011-03-14 21:20
>>10
i really dont know lol
13
Name:
Anonymous
2011-03-14 21:27
just tell me so i can get out of here, please.
14
Name:
Anonymous
2011-03-14 21:31
VIOLATE MY ANUS
15
Name:
Anonymous
2011-03-14 21:35
16
Name:
IHBT
2011-03-14 21:45
>>13
Future PHP programmer detected!
void strrvr(char strout[], char strin[])
// just because C gives shitty names to it's library functions
// doesn't mean you should. It's string_reverse, not strrvr
{
int n = strlen( strin ); // a rare correct line
int i = n; // notice that we need to initialise i
strout[i] = strout[n]; // copy the null string terminator
for (i = 0 ; i < n ; i++) // you want to loop up from i not down
strout[i] = strin[n-i-1]; // you were just writing a \0 to each element in strout
}
17
Name:
Anonymous
2011-03-14 21:54
const int buf_len = 100;
char in[buf_len] = "autism", out[buf_len];
int in_len = strlen(in), i = 0;
for(i = 0; i < in_len; i++)
#some forced indentation for good measure
out[i] = in[(in_len - i) + 1]; #fucking magnets here
out[i] = '\0';
or something
18
Name:
Anonymous
2011-03-14 21:54
>>16
this works however, i adds a lot of junk to the end of palindrom
19
Name:
Anonymous
2011-03-14 21:54
20
Name:
Anonymous
2011-03-14 21:55
How do we tell if a palidrome is sorted or not?
21
Name:
Anonymous
2011-03-14 21:59
>>18
Erm, if there is junk after the null, it is because it was there to begin with.
22
Name:
Anonymous
2011-03-14 22:03
>>21
its some random ass question marks, letters, and smiley faces
23
Name:
Anonymous
2011-03-14 22:30
#include "stdio.h"
#include "string.h"
// function prototypes
void string_reverse( char outstr[] , char instr[] );
// driver
int main()
{
char outstr[100];
char instr[100]= "emordnilap";
string_reverse(outstr, instr);
printf( "%s\n", outstr );
return( 0 );
}
void string_reverse(char strout[], char strin[])
{
int n = strlen( strin );
int i = n;
strout[i] = strout[n];
for (i = 0 ; i < n ; i++)
strout[i] = strin[n-i-1];
}
24
Name:
Anonymous
2011-03-14 23:05
>>16
You shouldn't be using C++ comments
C++ users use C++ comments
This behavior is unscientific and ultimately destructive.
25
Name:
Anonymous
2011-03-14 23:24
>>24
Shut the fuck up. /**/ is a stupid syntax.
26
Name:
Anonymous
2011-03-14 23:38
>>24-25
Having ; as statement separator instead of single-line comment marker is stupid.
27
Name:
Anonymous
2011-03-14 23:41
28
Name:
Anonymous
2011-03-14 23:51
29
Name:
Anonymous
2011-03-15 0:20
still cant figure out why i have junk at the end of palindrome
30
Name:
Anonymous
2011-03-15 3:02
31
Name:
IHBTT
2011-03-15 3:07
>>16
it's library functions
What about
it is library functions?
32
Name:
Anonymous
2011-03-15 7:45
>>16
int n = strlen( strin ); // a rare correct line
It's not correct, strlen returns a size_t.
33
Name:
Anonymous
2011-03-15 8:15
GNU/Optimized
/*This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/> ;. */
const __attribute__((always_inline)) static inline void
strrvr(char * __i,
char * __o)
{
size_t __p;
for ( __p=strlen(__i)-1;*__i!='\0';__i++,__p-- )
{
*( __o+__p )=*__i;
}
/* todo: make sure __o gets null terminated */
}
34
Name:
Anonymous
2011-03-15 10:34
>>32
then what should it be
35
Name:
Anonymous
2011-03-15 11:44
static void strrvr(const char *in, char *out, ssize_t n)
{
int i;
for (i = 0, n-=2; n >= 0; ++i, --n)
out[i] = in[n];
out[i] = '\0';
}
#ifdef TEST
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char in[] = "HAX NY AMUS";
char out[sizeof in];
strrvr(in, out, sizeof out);
puts(out);
return EXIT_SUCCESS;
}
#endif
36
Name:
Anonymous
2011-03-15 12:47
>>34
Why am I not surprised you should ask that,
size_t n = strlen( strin );
37
Name:
Anonymous
2011-03-15 13:32
>>33
OMG OPTIMIZED that for you.
const __attribute__((always_inline) (const)) static inline void
strrvr (const char * restricted __i, char * restricted __o)
{
size_t __p;
for (__p=strlen(__i)-1;*__i;__i++,__p--)
*(__o+__p)=*__i;
}
38
Name:
Anonymous
2011-03-15 14:03
>>37
Probably doable faster by abusing the stack, but what's the point with putting 2 underscores before the variable names?
39
Name:
Anonymous
2011-03-15 14:11
>>36
To all faggots who think size_t is a separate type and not an integer:
size_t is just a typedef, it even says so in the C99 standard
40
Name:
Anonymous
2011-03-15 14:20
>>39
To all faggots who think int == integer:
YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT
Newer Posts