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.
 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
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 User
 
Join Date: Dec 2007
Location: Canada, Prince Edward Island
Posts: 464
could you post your makefile and the error(s)...Thanks
gerard4143 is online now   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
Free Network Mapping Tool for Microsoft® Office Visio® Professional 2007 Users
Don't map your network by hand – let LANsurveyor Express for Microsoft Visio Professional 2007 automatically create network diagrams for you.
subscribe
Free eBook:"Vulnerability Management for Dummies"
Get all the Facts and See How to Implement a Successful Vulnerability Management Program.
subscribe
Google vs The World: The Battle of the Message Security Vendors
With such a powerful name behind it, Google Message Security stands out in a sea of products that do exactly the same thing - or so they say.
subscribe

Safe, Secure Backup


All times are GMT. The time now is 02:27 AM.






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

Content Relevant URLs by vBSEO 3.3.0 RC2