gpt4 book ai didi

c - 请帮助我的代码,编译问题

转载 作者:太空宇宙 更新时间:2023-11-04 06:42:29 26 4
gpt4 key购买 nike

<分区>

#include <stdio.h>
#include <malloc.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct node
{
char data[20];
char m[40];
int mcount;
struct node* next;
struct node* prev;
struct node* link;
} node;

struct node* dic ;

struct node* allocating ( int n ) ;
void add ( char* ) ;
int *search ( char* null, struct node* head ) ;
void show ( node* ) ;
int sorting ( char *, char * );
void delete_el ( node** head, node* p ) ;
int edit ( char* ) ;
int save ( node* head, char filename ) ;
int load ( node* head, char filename, int n ) ;

int main( void)
{
node *N = NULL ;
node *p ;
node *L ;
node *a ;
node *h ;
int n, nm, k, r, i ;
char filename [ 50 ] ;
char c_name [ 50 ] ;
char word [ 20 ] ;

r=0;

while(1)
{
r++;
system ( " cls " ) ;
puts ( "\t\t Dictionary Menu: \n" ) ;
puts ( "\t\t 1.Add. \n ") ;
puts ( "\t\t 2.Search. \n ") ;
puts ( "\t\t 3.Show. \n") ;
puts ( "\t\t 4.Edit. \n") ;
puts ( "\t\t 5.Delete. \n " ) ;
puts ( "\t\t 6.Compare. \n" ) ;
puts ( "\t\t 7.Save. \n" ) ;
puts ( "\t\t 8.Load. \n" ) ;
puts ( "\t\t 9.Clear. \n" ) ;
puts ( "\t\t 10.Quit. \n" ) ;

do
{
puts("\n Enter number of menu");
scanf("%d",&nm);

if ( nm==11 ) break ;
if ( ( r==1 ) && ( nm!=1 ) )
{
puts ( "\t\tAdd the word first!" ) ;
puts ( "\t\tPress any key to continue..." ) ;
getch ();
}
}
while((r==1)&&(nm!=1));
switch(nm)
{
case 1 ://INPUT
printf ( "\nEnter the word : " ) ;
fflush ( stdin ) ;
gets ( word ) ;
add ( word ) ;
break;

case 2 : //SEARCH

printf ( "\nEnter the word to search : " ) ;
fflush ( stdin ) ;
gets ( word ) ;
i = search ( word ) ;
if ( ! i )
printf ( "Word does not exist." ) ;
getch( ) ;

break ;

case 3 : //OUTPUT

show( word ) ;
getch( ) ;

break;

case 4 ://EDIT

printf ( "\nEnter the word you want to edit: " ) ;
fflush ( stdin ) ;
gets ( word ) ;
edit ( word ) ;
getch ( ) ;
break;


case 5 : //DELETE
printf("Enter name of country you want to delete: ");
fflush(stdin);
gets(c_name);
p = search(h,c_name);
//functia de jos NA
//delete1 (&h,p);
if (!p)
{
puts ("Operation was not performed");
puts ("Press any key to continue...");
//getch();
break;
}
else

puts ("Information about Country was deleted successfuly");
puts ("Press any key to continue...");
getch ();
break;




case 6 ://COMPARING


break;

case 7 ://SORTING
sorting( );

break;

case 8 ://SAVE TO FILE
printf ("Enter name of the file\n");
fflush(stdin);
gets(filename);
save(h,filename);
puts("Information was saved successfuly");
puts("Press any key to continue...");
getch ();
break;

case 9 ://LOAD FROM FILE
printf ("Enter name of the file\n");
fflush(stdin);
gets(filename);
n = length((h));
load(h,filename,n);
puts("Information was load successfuly");
puts("Press any key to continue...");
getch ();
break;

case 10 : //FREE MEMORY
//uncomment cand o creezi
//freememory( N );
printf("\n Press Enter to bring back the Menu");
getch();
break;

case 11 : //EXIT
//uncomment cand o creezi
//deldic( ) ;
exit ( 0 ) ;
}
}
}


node *allocating ( int n ) //ALLOCATING
{

node *head, *C, *p ;
int i;
for( i=0; i<n; i++ )
{
C = ( node* ) malloc ( sizeof ( *C ) ) ;
if ( !C )
{
puts ( "Memory was not allocated" ) ;
exit(1);
}
if( i == 0 )
{
head = C ;
}
else
{
p -> next = C ;
}
C -> next = NULL ;
p = C ;
}
return head ;
}

node *search( node *head, char *c_name ) //SEARCH
{
node *C ;
C = head ;

while ( C )
{
if ( strcmp ( C -> data, c_name ) == 0 )
{
return C;
}
C = C -> next ;
if ( C == head ) break ;
}
return NULL ;
}


void add ( node *head ) //ADDING
{
int i = 0 ;
int mozilla;
node *h;
puts ( "How many words do you want to add?" ) ;
scanf ( "%i", &mozilla ) ;
h = allocating ( mozilla ) ;

puts ( "Enter the words:\n" ) ;
while ( h )
{
printf("\t%d:\n", i+1 ) ;
i++ ;
puts ( "The word itself:\n" ) ;
fflush ( stdin ) ;
gets( h -> data [ i ] ) ;
puts ( "It's definition:\n" ) ;
fflush ( stdin ) ;
gets( h -> m[ i ] ) ;
if( h -> next == head ) break ;
h = h -> next ;
}
}

void show( ) //OUTPUT
{
struct node *n ;
int i, j ;

printf ( "Word\t\tMeaning\n" ) ;
for ( i = 0 ; i <= 30 ; i++ )
printf ( "-" ) ;


for ( i = 0 ; i <= 25 ; i++ )
{
n = dic [ i ] ;
while ( n != NULL )
{
printf ( "\n%s\t\t%s", n -> data, n -> m [ 0 ] ) ;
for ( j = 1 ; j < n -> mcount ; j++ )
printf ( "\n\t\t%s", n -> m [ j ] ) ;
n = n -> link ;
}
}
}

int length ( node *head ) //LENGTH
{
int l = 0 ;
node *C ;
C = head ;
while ( C )
{
C = C -> next ;
l++ ;
if( C == head ) break ;
}
return l ;
}

int save( node *head, char *filename ) //SAVE
{
FILE *fp ;
node *C ;
int i;
fp = fopen ( filename," w " ) ;
if ( !fp ) return 0 ;
C = head ;
while ( C )
{
fprintf ( fp, "%s %s \n" , C -> data [ i ] , C -> m [ i ] ) ;
C = C -> next ;
if ( C == head ) break ;
}
fclose ( fp ) ;
return 1 ;
}

int load(node *head, char *filename,int n) //LOAD
{
FILE *fp;
node *C;
int i;
fp = fopen ( filename, " r " ) ;
if ( !fp ) return 0 ;
C = head ;
while ( C )
{
fscanf ( fp, "%s %s \n" , &C -> data [ i ] , &C -> m [ i ] ) ;
if ( C -> next == head ) break ;
{
C = C -> next ;
}
}
fclose ( fp ) ;
return 1 ;
}
void delete_el ( node **head, node *p ) //DELETING
{
node *a ;

if ( *head == p )
{
p = *head ;
*head = p-> next ;
free ( p ) ;
return ;
}
else
{
a = *head ;
while ( a -> next != p )
{
a = a -> next ;
}
a -> next = p -> next ;
free ( p ) ;
return ;
}

}
//int sorting ( char *s1, char *s2 )
//{
// if ( strcmp ( s1, s2 ) == 0 ) return ( 0 ) ; //if they are equal
//
// for ( int i=0;s1[i]!=0;i++)
// {
// if ( data [ i ] > data [ i+1 ] ) return ( 1 ) ;
// else if ( s1 [ i ] < s2 [ i ] )return ( 2 ) ;
// }
//
// return ( 2 ) ; //hey if they are not equal and s1 not greater than s2 then s2 is greater
//}

我收到此错误消息:

C:\Users\user\Desktop\Untitled1.c||In function 'main':|
C:\Users\user\Desktop\Untitled1.c|96|warning: passing argument 1 of 'show' from incompatible pointer type|
C:\Users\user\Desktop\Untitled1.c|22|note: expected 'struct node *' but argument is of type 'char *'|
C:\Users\user\Desktop\Untitled1.c|115|warning: passing argument 1 of 'search' from incompatible pointer type|
C:\Users\user\Desktop\Untitled1.c|21|note: expected 'char *' but argument is of type 'struct node *'|
C:\Users\user\Desktop\Untitled1.c|115|warning: passing argument 2 of 'search' from incompatible pointer type|
C:\Users\user\Desktop\Untitled1.c|21|note: expected 'struct node *' but argument is of type 'char *'|
C:\Users\user\Desktop\Untitled1.c|115|warning: assignment from incompatible pointer type|
C:\Users\user\Desktop\Untitled1.c|149|warning: passing argument 2 of 'save' makes integer from pointer without a cast|
C:\Users\user\Desktop\Untitled1.c|26|note: expected 'char' but argument is of type 'char *'|
C:\Users\user\Desktop\Untitled1.c|160|warning: passing argument 2 of 'load' makes integer from pointer without a cast|
C:\Users\user\Desktop\Untitled1.c|27|note: expected 'char' but argument is of type 'char *'|
C:\Users\user\Desktop\Untitled1.c|209|error: conflicting types for 'search'|
C:\Users\user\Desktop\Untitled1.c|21|note: previous declaration of 'search' was here|
C:\Users\user\Desktop\Untitled1.c|227|error: conflicting types for 'add'|
C:\Users\user\Desktop\Untitled1.c|20|note: previous declaration of 'add' was here|
C:\Users\user\Desktop\Untitled1.c||In function 'add':|
C:\Users\user\Desktop\Untitled1.c|243|warning: passing argument 1 of 'gets' makes pointer from integer without a cast|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\stdio.h|356|note: expected 'char *' but argument is of type 'char'|
C:\Users\user\Desktop\Untitled1.c|246|warning: passing argument 1 of 'gets' makes pointer from integer without a cast|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\stdio.h|356|note: expected 'char *' but argument is of type 'char'|
C:\Users\user\Desktop\Untitled1.c||In function 'show':|
C:\Users\user\Desktop\Untitled1.c|253|error: number of arguments doesn't match prototype|
C:\Users\user\Desktop\Untitled1.c|22|error: prototype declaration|
C:\Users\user\Desktop\Untitled1.c|264|error: incompatible types when assigning to type 'struct node *' from type 'struct node'|
C:\Users\user\Desktop\Untitled1.c|289|error: conflicting types for 'save'|
C:\Users\user\Desktop\Untitled1.c|26|note: previous declaration of 'save' was here|
C:\Users\user\Desktop\Untitled1.c|307|error: conflicting types for 'load'|
C:\Users\user\Desktop\Untitled1.c|27|note: previous declaration of 'load' was here|
||=== Build finished: 7 errors, 8 warnings ===|

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com