Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > I have a program to compile,need help.

Forgot Password?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 10-15-2008   #1 (permalink)
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;

}
wxjeacen is offline  


Reply With Quote
Old 10-15-2008   #2 (permalink)
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.
wowbag1 is offline   Reply With Quote
Old 10-15-2008   #3 (permalink)
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("%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;

}
wxjeacen is offline   Reply With Quote
Old 10-15-2008   #4 (permalink)
Linux Enthusiast
 
Join Date: Dec 2007
Location: Canada, Prince Edward Island
Posts: 524
could you post your makefile and the error(s)...Thanks
gerard4143 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 06:18 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2