PDA

View Full Version : سوال: اشکال این برنامه کجاشه؟ (C)



sahar.d72
یک شنبه 04 دی 1390, 22:17 عصر
سلام این برنامه رو با c نوشتم اما error میده
کسی میتونه کمک کنه؟؟؟






#include <stdio.h>
#include <stdlib.h> //tolide adade tasadofi dar rand
#define I 9
#define J 3

//function prototypes
int binarySearch(const int a[][1],int searchkey,int low,int high);
void printHeader();
void insertionSort(int a[][1],int I);
void printPass(int a[][1], int I);

int a[I][J];
char vaziat;
int stdno;
char name;
char a[16][0]=name; //namo name khanevadegi ba 15 char English va chare pooche payani
int a[I][1]=key; //kode melli
char a[I][2]=vaziat; //vaziat
int a[I][3]=stdno; //shomare daneshjui


int main()
{
printf("amaliate morede nazar ra entekhab konid\n");
printf("1:namayeshe liste moshakhaste daneshjuyan\n");
printf("2:jostejuye daneshju\n");

while(amaliat=getchar()) != EOF)//while1
{
switch(amaliat){//switch1

case '1':

//moshakhasate yek daneshjuye farzi
char a[0][0]="Mina Alavi"
int a[0][1]={1275434466}
char a[0][2]="Roozane"
int a[0][3]={9023455}
for(I=0; I<10; I++){
while (J<=3){
printf("%p", a[I][J]);
J++;
}//end while
}//end for
break;

case '2':

void insertionSort (int a[][1], int I) //sort bar asase kode melli
{
int insert; //temporary variable to hold element insert
int I;
for(i=1;i<I; i++){
int moveItem=I;
insert=a[i][1];
while (moveItem>0 && a[moveItem-1][1]>insert){
a[moveItem]=a{moveItem-1];
--moveItem;
}//end while

a[moveItem][1]= insert;
a[moveItem]=insert; //place inserted element
printPass( a,I,I,moveItem);
}//end for
}//end function insertionSort

int i;
int key;
int result;
for(i=0; i<I;i++)
{
a[i]=2*i
}
printf("kode mellie daneshju ra vared konid");
scanf("%d", &key);
printHeader();
result=binarySearch(a,key,0,I);
if(result != -1){
printf("\n %d found in array element %d\n", key, result);
printf("\n vaziate daneshju : ");
printf("%s", a[result][2]);
}
else{
printf("\n %d yaft nashod\n", key);
printf("sabte nam mikonid? \n baraye sabte nam kelide 1 va baraye khoruj kelide 2 ra feshar dahid.");
while((kelid=getchar()) != EOF){//while2
switch(kelid){//switch2
case '1':
stdno=rand()
printf("\n shomareye daneshjui : %d", stdno);
printf("name daneshju ra vared konid:\n");
scanf("%s", name);
printf("vaziat? Roozane – amoozeshe electronic\n");
scanf("%s", &vaziat);

printf("sabte name %s ba kode mellie %d va shomare daneshjuie %d ba movafaghiat anjam shod\n vaziat: %s", name, key, stdno, vaziat);

case '2';

return -1; //exit
}//end switch2
}//end while2
}//end switch1
}//end while1
}//end main

BeginnerProgrammer
یک شنبه 04 دی 1390, 23:52 عصر
ارورهای برنامه اش خیلی واضحه !
اسم همه متغیرهاaست یه جای دیگه م یکی از بعدهای آرایه رو 0 دادی که اشتباس. اینا رو برطرف کنی مشکلت حل میشه

sahar.d72
دوشنبه 05 دی 1390, 00:54 صبح
ارورهای برنامه اش خیلی واضحه !
اسم همه متغیرهاaست یه جای دیگه م یکی از بعدهای آرایه رو 0 دادی که اشتباس. اینا رو برطرف کنی مشکلت حل میشه توی کل برنامه از یه ارایه استفاده کردم که اونم اسمشو گذاشتم a.
متغیرها رو اسم یکسان نذاشتم. بعد ارایه ها رو درست کردم اما هنوز ارور میده.
error C2440: 'initializing' : cannot convert from 'char' to 'char [9][3]
error C2143: syntax error : missing ')' before 'constant

BeginnerProgrammer
دوشنبه 05 دی 1390, 08:23 صبح
int a[I][J];
char a[16][0]=name; //namo name khanevadegi ba 15 char English va chare pooche payani
int a[I][1]=key; //kode melli
char a[I][2]=vaziat; //vaziat
int a[I][3]=stdno; //shomare daneshjui

همین چند خط کد تمام آرایه ها اسمشون aس با تعریفها مختلف این قسمتا رو اصلاح کن تا ارورای بعدیم مشخص بشه

sahar.d72
دوشنبه 05 دی 1390, 08:53 صبح
#include <stdio.h>


#include <stdlib.h> //tolideadade tasadofi dar rand

#define I 9

#define J 3

//functionprototypes

intbinarySearch(const intkey[][2],int searchkey,intlow,int high);

voidprintHeader();

voidinsertionSort(int key[][2],int I);

void printPass(int key[][2], int I);



int a[I][J];

char vaziat;

int stdno;

char name;

charname[16][1]=name; //namo name khanevadegi ba 15 charEnglish va chare pooche payani

intkey[I][2]=key; //kode melli

charvaziat[I][3]=vaziat; //vaziat

intstdno[I][4]=stdno; //shomare daneshjui

int main()

{

printf("amaliate morede nazar ra entekhab konid\n");

printf("1:namayeshe liste moshakhaste daneshjuyan\n");

printf("2:jostejuye daneshju\n");

while(amaliat=getchar())!= EOF)//while1

{

switch(amaliat){//switch1

case '1':



//moshakhasateyek daneshjuye farzi

char a[1][1]="Mina Alavi"

inta[1][2]={1275434466}

char a[1][3]="Roozane"

inta[1][4]={9023455}

for(I=1;I<=10; I++){

while(J<=4){

printf("%p",a[I][J]);

J++;

}//endwhile

}//endfor

break;

case '2':

voidinsertionSort (int key[][2], int I) //sort barasase kodemelli

{

int insert; //temporary variable to hold element insert

int I;

for(i=1;i<I;i++){

intmoveItem=I;

insert=key[i][2];

while(moveItem>0 && key[moveItem-1][2]>insert){

key[moveItem][2]=key[moveItem-1][2];

--moveItem;

}//endwhile

key[moveItem][2]= insert;

key[moveItem][2]=insert; //place inserted element

printPass(key,I,I,moveItem);

}//endfor

}//endfunction insertionSort

int i;



int key;

int result;

for(i=1;i<=I;i++)

{

key[i][2]=2*i

}

printf("kode mellie daneshju ra vared konid");

scanf("%d", &key);

printHeader();

result=binarySearch(a,key,1,I);

if(result !=-1){

printf("\n %d found in array element %d\n",key,result);

printf("\n vaziate daneshju : ");

printf("%s", key[result][2]);

}

else{

printf("\n %d yaft nashod\n", key);

printf("sabte nam mikonid? \n baraye sabte nam kelide 1 vabaraye khoruj kelide 2 ra feshar dahid.");

while((kelid=getchar())!= EOF){//while2

switch(kelid){//switch2

case '1':

stdno=rand()

printf("\n shomareye daneshjui : %d", stdno);

printf("name daneshju ra vared konid:\n");

scanf("%s", name);

printf("vaziat? Roozane – amoozeshe electronic\n");

scanf("%s", &vaziat);

printf("sabte name %s ba kode mellie %d va shomaredaneshjuie %d ba movafaghiat anjam shod\n vaziat: %s",name, key,stdno, vaziat);

case '2';



return -1; //exit

}//endswitch2

}//endwhile2

}//endswitch1

}//endwhile1
}//end main

BeginnerProgrammer
دوشنبه 05 دی 1390, 09:42 صبح
char a[1][1]="Mina Alavi";

int a[1][2]={1,2,7,5,4,3,4,4,6,6}

char a[1][3]="Roozane";

int a[1][4]={9,0,2,3,4,5,5}

for(I=1;I<=10; I++)

خط اول که چون آرایه کاراکتری یک در یک فقط ظرفیت یک کارکتر داره (فقط کدی مثل کد زیر قابل قبوله):

char a[1][1]={'M'};
خط بعد هم ظرفیت سه کاراکتر رو داره برای اینکه نام و نام خانوادگی یا وضعیتو بررسی کنید میتونید یه آرایه یک بعدی با طول مثلا 50 کاراکتر بگیرید(کلا نیازی به آرایه دو بعدی نیست.)
خط سوم هم که آرایه میتونه 3 عدد اینت ذخیره کنه در حالی که شما بیشتر عدد دادین و یک خطای کلی اینکه اسم این 3 آرایه aست.
ارور دیگم مربوط به استفاده از I در حالی که به عنوان یک متغیر با مقدار ثابت تعریف کردین از جمله تو این خطها:

for(I=1;I<=10; I++)
void insertionSort(int key[][2],int I);

void printPass(int key[][2], int I);

sahar.d72
دوشنبه 05 دی 1390, 11:56 صبح
درست نشد...


#include

<stdio.h>

#include

<stdlib.h> //tolide adade tasadofi dar rand



//function prototypes

int

binarySearch(const int key[],int searchkey,int low,int high);

void

printHeader();

void

insertionSort(int key[], 10);

void

printPass(int key[], 10);



char

vaziat;

int

stdno;

char

name;

char

name[16]=name; //namo name khanevadegi ba 15 char English va chare pooche payani

int

key[10]=key; //kode melli

char

vaziat[]=vaziat; //vaziat

int

stdno[]=stdno; //shomare daneshjui

int

main()

{

printf(
"amaliate morede nazar ra entekhab konid\n");

printf(
"1:namayeshe liste moshakhaste daneshjuyan\n");

printf(
"2:jostejuye daneshju\n");

while

(amaliat=getchar()) != EOF)//while1

{

switch

(amaliat){//switch1

case

'1':




//moshakhasate yek daneshjuye farzi

char

name[]="Mina Alavi"

int

key[]={1275434466}

char

vaziat[]="Roozane"

int

stdno[]={9023455}



printf(
"%c\t %d\t %c\t %d\t", name[], key[], vaziat[],stdno[]);



break

;

case

'2':


void insertionSort (int key[],10) //sort barasase kode melli

{

int

insert; //temporary variable to hold element insert

for

(i=1;i<10; i++){

int

moveItem=i;

insert=key[i];

while

(moveItem>0 && key[moveItem-1]>insert){

key[moveItem]=key[moveItem-1];

--moveItem;

}
//end while

key[moveItem]= insert;

key[moveItem]=insert;
//place inserted element

printPass( key,10,i,moveItem);

}
//end for

}
//end function insertionSort



int

key[10];

int

result;

int

code;

for

(i=1; i<=10;i++)

{

key[i]=2*i

}

printf(
"kode mellie daneshju ra vared konid");

scanf(
"%d", &code);

printHeader();

result=binarySearch(key,code,0,9);

if

(result != -1){

printf(
"\n %d found in array element %d\n", code,result);

printf(
"\n vaziate daneshju : ");

printf(
"%s", key[result][2]);

}


else{

printf(
"\n %d yaft nashod\n", code);

printf(
"sabte nam mikonid? \n baraye sabte nam kelide 1 va baraye khoruj kelide 2 ra feshar dahid.");


while((kelid=getchar()) != EOF){//while2


switch(kelid){//switch2

case

'1':

stdno=rand()

printf(
"\n shomareye daneshjui : %d", stdno);

printf(
"name daneshju ra vared konid:\n");

scanf(
"%s", name);

printf(
"vaziat? Roozane amoozeshe electronic\n");

scanf(
"%s", &vaziat);

printf(
"sabte name %s ba kode mellie %d va shomare daneshjuie %d ba movafaghiat anjam shod\n vaziat: %s",name, code, stdno, vaziat);

case

'2';




return -1; //exit

}
//end switch2

}
//end while2

}
//end switch1

}
//end while1

}
//end main