a sort function

hi im new here
Im searching for a function that a letter can place at end of the word
in the program you must firts read the word(school) and a number(3)
than must be the first 3 letters of the word go to the end of the word
like this => "OOLSCH"
i have a program but it dont work, every time they say that there are things that not are declared.
Is there someone who can help me !!

here is my program:


#include "stdafx.h"
#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
#define AANTAL 20


void schuiven(char *woord)
{
char nieuwwoord[AANTAL];
int lengte = strlen(woord);
int i,x;
int codeer;

for(int a=0;a<=(codeer-1);a++)
{
for(x=0;x<=(lengte-1);x++)
{
nieuwwoord[(lengte-1)-x]=woord[(lengte-2)-x];
}

}

printf("de verschoven naam is %c",nieuwwoord[i]);
}


int _tmain(int argc, _TCHAR* argv[])
{
char woord[AANTAL];
int lengte;
int codeer;
char *pointerwoord;
char keuze,enter;

do{
system("cls");
printf("Geef een woord in: ");
scanf("%s%c",&woord,&enter);
lengte = strlen(woord);

do{
printf("Geef een codeercijfer in: ");
scanf("%i%c",&codeer,&enter);
if(codeer > lengte)
{
printf("FOUT,Uw codeercijfer moet kleiner zijn!\n");
}

}while(codeer > lengte);


schuiven(woord);


printf(" Geef een J voor door tegaan een N voor te stoppen: ");
scanf("%c",&keuze);

}while(keuze == 'J' || keuze == 'j');
scanf(" ");
return 0;
}
I'm not eager to read your code so I'll just write my own:
1
2
3
4
5
6
char str[20] = "school";
int len = 3;
char result[20];
memcpy(result, str+len, strlen(str)-len);//or 'for(int i = 0; i < strlen(str)-len; i++) result[i] = str[len+i];
memcpy(result+len, str, len);
result[strlen(str)] = '\0';


Or you could do it with c++ strings:
1
2
string str = "school";
string result = string(str, 3) + string(str, 0, 3);


By the way, this is not sorting..

Hi,

What you're doing is the first step of block sorting (i.e., without the sorting). So hamsterman is correct -- it isn't sorting. In addition to the code he gave, I think you can find examples on the Web by searching for "block sorting" or "Burrows Wheeler transform"...

Ray

Topic archived. No new replies allowed.