Komutlara bakarken sadece boşluk karakteri aramışsınız. "help" ve gibi
parametresiz komutlarda while döngünüz "segmentation fault" hatasına
kadar dönüyor. while(comand[i]!=32) yerine while(comand[i]!=32 &&
command [i] != 0x00 ) olarak deneyin.
Birde Arkadaş Yayın evinden çıkan, "Hatasız Kodlama" kitabını herkese
tavsiye ederim. Microsoft'un yaptığı vahim hatalardan da bahseden
genelde böceksiz yazılımın nasıl hazırlanması gerektiği konusunu ele
alan bir kitap. Özellikle string işlemler ile ilgili güzel örnekler vardı.
"Hatasız Kodlama"
Yazarı : Steve Maguire
Çeviri : Ceyhan TEMÜRCÜ , Olcay ESKİBASKETÇİ,
ISBN : 9755090940
Kolay gelsin.
-- Aykut KOÇAK Elektronik Mühendisi E-Posta :aykutkocak_at_superonline.com Web : http://www.gprskamera.com http://www.abesis.net YILDIRIM yazmış: >>> Linux altında gcc kullanarak derleme yaptığımda string.h kütüphanesinde >>> bulunan gets(), strcmp() gibi string fonksiyonlarından kaynaklanan >>> "segmentation fault" hataları alıyorum. Bu problemi çözmenin bir yolu >>> var mıdır? >>> Şimdiden yardımcı olan arkadaşlara teşekkür ederim. >>> >>> Mehmet Salih YILDIRIM >>> _______________________________________________ >>> Linux-programlama mailing list >>> Linux-programlama_at_liste.linux.org.tr >>> http://liste.linux.org.tr/mailman/listinfo/linux-programlama >>> >>> >>> _______________________________________________ >>> Linux-programlama mailing list >>> Linux-programlama_at_liste.linux.org.tr >>> http://liste.linux.org.tr/mailman/listinfo/linux-programlama >>> >>> >>> Aşağıda bi programın şablonu olarak hazırladığım kodlar bulunmakta. >>> Arkadaşım windows altında bir derleyiciyle (dev c) derlediğinde sorunsuz >>> çalışıyor. Fakat Linux altında gcc ile derlediğimde derleme başarılı oluyor >>> fakat "help" komutu gibi komutları verdiğimde "segmentation fault" verip >>> programı sonlandırıyor. Sorunun string.h kütüphanesindeki fonksiyonlardan >>> kaynaklandığını düşünüyorum. İlgilenen herkese teşekkür ederim. >>> >>> Mehmet Salih YILDIRIM >>> >>> >>> <code> >>> >>> // prevent program crash when using commands with no >>> parameters or with not expected value of parameters // >>> // for whoami and logout it is not necacery to define them as >>> a "program" // >>> >>> >>> >>> // ANA PROGRAM // >>> >>> #include <stdio.h> >>> //#include <stdlib.h> >>> #include <string.h> >>> >>> >>> >>> static char actvusr[20]="testuser"; >>> >>> >>> int main () { >>> >>> char pathp[20]; >>> char param2[20]; >>> char param1[20]; >>> char cmd[20]; >>> char comand[20]; >>> int i,j,k; >>> >>> printf("\n\n\n Welcome FS-1a \n"); >>> printf("\n by A.Egitmen & M.S.Yildirim\n\n\n"); >>> printf("\n For instructions type 'help'\n\n\n"); >>> >>> >>> >>> do { >>> printf("/%s>",actvusr); >>> gets(comand); >>> i=0; >>> j=0; >>> k=0; >>> while(comand[i]!=32){ >>> cmd[i]=comand[i]; >>> i++; >>> } >>> cmd[i]='\0'; >>> i++; >>> >>> >>> //______________________________________________________________________________________________________________ >>> >>> >>> /*help*/ if(!strcmp(cmd,"help")){ >>> >>> printf("\n Login Usage : login >>> 'username'\n "); >>> printf("\n Dir Usage : dir >>> 'pathname'\n"); >>> printf("\n Copy Usage : cp >>> 'source''FILENAME' 'destination''FILENAME'\n"); >>> >>> printf("\n Delete Usage : del >>> 'source2''FILENAME'\n"); >>> printf("\n ReaderList Usage : rl\n" ); >>> printf("\n Receive Usage : receive >>> 'FILENAME'\n"); >>> printf("\n Send Usage : send 'FILENAME' >>> 'USERNAME'\n"); >>> printf("\n Whoami Usage : whoami\n"); >>> printf("\n Setpass Usage : setp\n"); >>> printf("\n Logout Usage : logout\n"); >>> printf("\n Exit Usage : exit\n"); >>> >>> >>> } >>> >>> //_____________________________________________________________________________________________________________ >>> >>> >>> /*login*/ else if(!strcmp(cmd,"login")){ >>> if(strcmp(actvusr,"\0")){ >>> printf("\n You Have Already Logged \n"); >>> } >>> else{ >>> >>> while(comand[i]!=32){ >>> param1[j]=comand[i]; >>> i++; >>> j++; >>> } >>> param1[j]='\0'; >>> >>> printf("\n command : %s\n",cmd ); >>> printf("\n param1 : %s\n",param1); >>> // - login call - if pass match return => >>> actvuser=username >>> // write system date to lastlogin.txt >>> // find username from actvuser.dat and write 1 to there >>> // you will rechange it to 0 when logout >>> } >>> } >>> >>> //___________________________________________________________________________________________________________ >>> >>> /*dir*/ else if(!strcmp(cmd,"dir")){ >>> if(!strcmp(actvusr,"\0")){ >>> printf("\n Please Login Before Using Commands\n"); >>> } >>> else{ >>> while(comand[i]!=32){ >>> param1[j]=comand[i]; >>> i++; >>> j++; >>> } >>> param1[j]='\0'; >>> printf("\n command : %s\n",cmd ); >>> printf("\n param1 : %s\n",param1); >>> >>> // call dir , print files while in dir; return >>> void >>> } >>> >>> } >>> >>> //_____________________________________________________________________________________________________________ >>> >>> >>> /*COPY*/ else if(!strcmp(cmd,"cp")){ >>> if(!strcmp(actvusr,"\0")){ >>> printf("\n Please Login Before Using >>> Commands\n"); >>> } >>> else{ >>> >>> while(comand[i]!=32){ >>> param1[j]=comand[i]; >>> i++; >>> j++; >>> } >>> param1[j]='\0'; >>> >>> i++; >>> while(comand[i]!=32){ >>> param2[k]=comand[i]; >>> i++; >>> k++; >>> } >>> param2[k]='\0'; >>> printf("\n command : %s\n",cmd ); >>> printf("\n param1 : %s\n",param1); >>> printf("\n param2 : %s\n",param2); >>> i=0; >>> while(param1[i]!=47){ >>> pathp[i]=param1[i]; >>> i++; >>> } >>> pathp[i]='\0'; >>> >>> printf("\n path : %s\n",pathp); >>> >>> //get user id from uid ; with uid get supervisor >>> information from users.dat >>> //if ok then call cp >>> //if not get read permision for pathp from permis.txt >>> //if ok call cp ; >>> //if not cancel it >>> //--call cp-- return nothing// >>> >>> } >>> } >>> >>> //_____________________________________________________________________________________________________________ >>> >>> >>> /*DELETE*/ else if(!strcmp(cmd,"del")){ >>> if(!strcmp(actvusr,"\0")){ >>> printf("\n Please Login Before Using >>> Commands\n"); >>> } >>> else{ >>> while(comand[i]!=32){ >>> param1[j]=comand[i]; >>> i++; >>> j++; >>> } >>> param1[j]='\0'; >>> printf("\n command : %s\n",cmd ); >>> printf("\n param1 : %s\n",param1); >>> while(param1[i]!=47){ >>> pathp[i]=param1[i]; >>> i++; >>> } >>> pathp[i]='\0'; >>> >>> printf("\n path : %s\n",pathp); >>> //get user id from uid ; with uid get supervisor >>> information from users.dat >>> //if ok then call del >>> //if not get read permision for pathp from permis.txt >>> //if ok call del ; >>> //if not cancel it >>> //--call del-- return nothing// >>> >>> } >>> } >>> >>> //_____________________________________________________________________________________________________________ >>> >>> >>> /*ReaderList*/ else if(!strcmp(cmd,"rl")){ >>> if(!strcmp(actvusr,"\0")) { >>> printf("\n Please Login Before Using Commands\n"); >>> } >>> else{ >>> >>> //call rl ; in rl open spool/username/files.txt >>> //read it line by line write it and return void >>> >>> } >>> } >>> >>> //_______________________________________________________________________________________________________________ >>> >>> /*Whoami*/ else if(!strcmp(cmd,"whoami")){ >>> if(!strcmp(actvusr,"\0")){ >>> printf("\nUnidentified Person\n"); >>> } >>> else{ >>> printf("\n %s \n",actvusr); >>> } >>> } >>> >>> //_______________________________________________________________________________________________________________ >>> >>> /*Logout*/ else if(!strcmp(cmd,"logout")){ >>> if(!strcmp(actvusr,"\0")){ >>> printf("\n You Are Not Seems to be Logged\n"); >>> } >>> else{ >>> printf("\n Thank You For Using FS-1a Please Contact >>> alper_egitmen_at_hotmail.com For Bugs \n" ); >>> actvusr[0]='\0'; >>> >>> } >>> >>> } >>> >>> //________________________________________________________________________________________________________________ >>> >>> >>> /*SEND*/ else if(!strcmp(cmd,"send")){ >>> if(!strcmp(actvusr,"\0")) { >>> printf("\n Please Login Before Using Commands\n"); >>> } >>> else{ >>> while(comand[i]!=32){ >>> param1[j]=comand[i]; >>> i++; >>> j++; >>> } >>> param1[j]='\0'; >>> >>> i++; >>> while(comand[i]!=32){ >>> param2[k]=comand[i]; >>> i++; >>> k++; >>> } >>> param2[k]='\0'; >>> printf("\n command : %s\n",cmd ); >>> printf("\n param1 : %s\n",param1); >>> printf("\n param2 : %s\n",param2); >>> >>> } >>> >>> >>> // call send without any permission check >>> >>> } >>> >>> >>> >>> //_________________________________________________________________________________________________________________ >>> >>> >>> >>> /*Receive*/ else if(!strcmp(cmd,"receive")) { >>> if(!strcmp(actvusr,"\0")) { >>> printf("\n Please Login Before Using Commands\n"); >>> } >>> else{ >>> while(comand[i]!=32){ >>> param1[j]=comand[i]; >>> i++; >>> j++; >>> } >>> param1[j]='\0'; >>> strcpy(param2,actvusr); >>> >>> printf("\n command : %s\n",cmd ); >>> printf("\n param1 : %s\n",param1); >>> printf("\n param2 : %s\n",param2); >>> >>> //call receive without any permission chech >>> >>> >>> } >>> >>> } >>> >>> >>> //________________________________________________________________________________________________________________ >>> >>> >>> >>> >>> /* SETPASS*/ else if(!strcmp(cmd,"setp")){ >>> if(!strcmp(actvusr,"\0")) { >>> printf("\n Please Login Before Using Commands\n"); >>> } >>> else{ >>> >>> //get id from uid , using id get information >>> "setpass" from users.dat >>> //if ok ; than as for old pass >>> //if ok ask new pass >>> //change pass with using id from passwd.dat >>> } >>> >>> } >>> >>> //_______________________________________________________________________________________________________________ >>> >>> // commands ends // >>> >>> else if(!strcmp(cmd,"\0")); >>> >>> else >>> printf("\n\n Unknown Command\n\n"); >>> >>> >>> } >>> >>> >>> >>> >>> >>> >>> >>> while(strcmp(cmd,"exit")); >>> >>> >>> >>> >>> return 0; >>> >>> } >>> >>> </code> >>> >>> _______________________________________________ >>> Linux-programlama mailing list >>> Linux-programlama_at_liste.linux.org.tr >>> http://liste.linux.org.tr/mailman/listinfo/linux-programlama >>> >>> >>> >> _______________________________________________ >> Linux-programlama mailing list >> Linux-programlama_at_liste.linux.org.tr >> http://liste.linux.org.tr/mailman/listinfo/linux-programlama >> >> > Teşekkür ederim. gdb yi incelemeye başlıyorum. > Tekrar kolay gelsin. > > > ------------------------------------------------------------------------ > > _______________________________________________ > Linux-programlama mailing list > Linux-programlama_at_liste.linux.org.tr > http://liste.linux.org.tr/mailman/listinfo/linux-programlama _______________________________________________ Linux-programlama mailing list Linux-programlama_at_liste.linux.org.tr http://liste.linux.org.tr/mailman/listinfo/linux-programlamaReceived on Thu 10 Jan 2008 - 08:32:11 EET