ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Originally posted by kponenation thank you dmail for your help but i can't include string.h so i can't use strcpy()
i know it would be a lot easier if i can but i just can't...
really? why cant you include "string.h"? the header is a standard c header isn't it?
in that case you cant use memcpy either.
looking at your earlier code
Code:
*word_array[i] = *word_array[i+1];
what this does is copy one char across and if you cant use string.h you may have to do this with 2d array for the lenght of the second index, to copy fully the string over.
another option is to create a struct string which looks something like
typedef struct tag_string
{
char* string;
int length;
}string,*p_string;
i modified it like this
[CODE]int sort(char **word_array, int N ){
int i = 0;
int j = 0;
char *tmpArray[width];
int result;
while (i < N){
while(j < N-1){
result = compare_words(word_array[j], word_array[j+1]);
printf("%d",result);
if(result == 0){
tmpArray[j]= word_array[j];
word_array[j] = word_array[j+1];
word_array[j+1] = tmpArray[j];
}
j = j +1;}
i = i + 1;}
return 0;
}
i tested w/ 5 words
word_array[0] = sad
word_array[1] = toy
word_array[2] = doom
word_array[3] = send
word_array[4] = cotton
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.