Find the answer to your Linux question:
Results 1 to 4 of 4
/*This program is to permute some letters of alphabet. However i can not compile it . There are always many errors. your help will be appreciated deeply. I am a ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2

    Unhappy I have a program to compile,need help.



    /*This program is to permute some letters of alphabet.
    However i can not compile it .
    There are always many errors.
    your help will be appreciated deeply.
    I am a new guy in Ubuntu .*/

    #include<stdio.h>
    #include<string.h>
    int L;
    void insort(int n,char *s,char c[]);


    void insort(int n,char *s,char c[])
    {
    char *d;
    char *str1,*str2;
    int i;
    if(n==0) *s=c[n];
    for(i=n;i>=0;i--)
    { d=s;
    memcpy(str1,d,i);
    str2=d+i;
    strcat(str1,c[n]);
    strcat(str1,str2);
    d=str1;
    if (n==L)printf("%s\n",d);
    }
    if (n+1<=L)
    insort(n+1,s,c);


    }




    int main()

    { char *str='\0';

    char S[];
    printf("The letters to permuted are:");
    scanf("%s
    ",S);
    L =strlen(S);

    insort(0,str,S);

    printf("\n");
    return 0;

    }

  2. #2
    Linux Newbie
    Join Date
    Jan 2008
    Location
    UK
    Posts
    211
    Hi,
    after giving a size to char S[] and scanf() put on one line.
    Compiling it I found only one major error and that was

    arg 2 of strcat is pointer from integer without a cast.

    so check casting in C then it will not get seg fault - which I am assuming you are getting.

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2
    /*I revised my programe ,corrected the error of the usage of "strcat".
    still I can`t pass the compiling .
    would someone post the code that can be compiled correctly .
    your help will be well appreciated .
    the code i given below */



    #include<stdio.h>
    #include<string.h>
    int L;
    void insort(int n,char s[],char c[]);


    void insort(int n,char s[],char c[])
    {
    char d[50];
    char str1[50],*str2;
    int i;
    if(n==0) s[n]=c[n];
    else{ for(i=n;i>=0;i--)
    { memcpy(d,s,strlen(s));
    d[strlen(s)]='\0';
    memcpy(str1,d,i);
    str1[i]='\0';
    str2=d+i;
    strcat(str1,c[n]);
    strcat(str1,str2);
    //d=str1;
    memcpy(d,str1,strlen(str1));
    d[strlen(str1)]='\0';
    if (n==L)printf("&#37;s\n",d);
    }
    }
    if (n+1<=L)
    insort(n+1,s,c);


    }




    int main()

    { char str[1000];
    str[0]='\0';

    char S[]="abcd";

    L =strlen(S);

    insort(0,str,S);

    return 0;

    }

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    705
    could you post your makefile and the error(s)...Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •