I am writing this exercise of bubble sort and I have to create 2 source files. The first contains the main code and the second contains my bubble sort algorithm. The main code includes the bubblesort.
Main:
#include<stdio.h>
#include<string.h>
#include"2.c"
int main(void)
{
char text[100];
int length;
printf("Insert text: \n");
gets(text);
text=bsort(text);
printf("String : %s \n",text);
return 0;
}
Bubblesort:
char *bsort(char text[100]){
char temp[100];
int length,i,j;
length=strlen(text);
for(i=1;i<length;i++){
for(j=0;j<length-i;j++){
if(text[j]>text[j+1]){
temp[0]=text_input[j]; //
text_input[j]=text_input[j+1];//Edit,had wrong code posted
text_input[j+1] =temp[0]; //
}
}
}
return text;}
The thing is ,when i run it, i get a " incompatible types when assigning to type 'char[100]' from type 'char *'" error
I'm terribly new to c and I'm kinda lost, I'm browsing for an answer for quite some hours now. I understand that the function will return a char instead of char array(known as a string from java experience), but I just can't get to find a way to do this as hard as I try.
A solution would be great or just a small help would be appreciated.
EDIT: I forgot to mention what my program actually does. It is supposed to get a string from the user, apply the bubblesort algorithm which is is going to sort every character in the string alphabetically, i.e. "bagf" will be output as "abfg". Also added some comments