Home > Back-end >  Why there is an error on this program in c 6.0 I college students just contact program adjure everyb
Why there is an error on this program in c 6.0 I college students just contact program adjure everyb

Time:10-06

#include
#include
#include /* text stored in the form of a string, each row between line and line to linked lists to store */
Typedef struct line
{
Char * data;
Struct line * next;
} the LINE;/* create a linked list, at the same time to input text data */
Void the Create (LINE * head)
{
Printf (" please enter a page to Ctrl + E (^ E) to end (lines enter a maximum of 80 characters! : \ n ");
The LINE * p=new LINE;/*, first of all, build an additional header for linked list node */
The head=p;/* will pay the header pointer p */
Char TMP [100].
While (1)
{
Gets (TMP);/* input string! */
If (strlen (TMP) & gt; 80)
{
Printf (" input a maximum of 80 characters per line ");
break;
}
If (TMP [0]==5) break;/* if it is found that the input ^ E, retreat to enter */
P=p - & gt; Next=new LINE;
P - & gt; data=https://bbs.csdn.net/topics/new char [strlen (TMP) + 1);/* to allocate space */
Strcpy (p - & gt; The data, TMP);
If (TMP [strlen (TMP) - 1)==5)/* to remove the last control characters ^ E */
{
P - & gt; Data [strlen (TMP) - 1]='\ 0';
break;
}
}
P - & gt; next=NULL;/* pointer is null, the last of */
The head=head - & gt; next;
}
/* statistics alphabetic */
Int CountLetter (LINE * & amp; The head)
{
The LINE * p=head;
Int count=0;
Do
{
Int Len=strlen (p - & gt; data);/* to calculate the number of data elements present in the data */
for(int i=0; iIf ((p - & gt; Data [I] & gt;='a' & amp; & P - & gt; Data [I] <='z') | | (p - & gt; Data [I] & gt;='A' & amp; & P - & gt; Data [I] <='Z'))/* calculation of letters */
count++;
}
While ((p=p - & gt; Next)!=NULL); Traverse the list/* */
return count; Total number of letters/* return article */
}
/* count words */
Int CountNumber (LINE * & amp; The head)
{
The LINE * p=head;
Int count=0;
Do
{
Int Len=strlen (p - & gt; data);/* to calculate the number of data elements present in the data */
for(int i=0; iIf (p - & gt; Data [I] & gt;=48 & amp; & P - & gt; Data [I] <=57) count++;
/* number of figures, ASCII */
}
While ((p=p - & gt; Next)!=NULL); Traverse the list/* */
return count;
}
/* statistical Spaces for */
Int CountSpace (LINE * & amp; The head)
{
The LINE * p=head;
Int count=0;
Do
{
Int Len=strlen (p - & gt; data);/* to calculate the number of data elements present in the data */
for(int i=0; iIf (p - & gt; Data [I]==32) count++;/* calculation of blank, the blank space ASCII is 32 */
}
While ((p=p - & gt; Next)!=NULL); Traverse the list/* */
return count;
}
Total number of words *//* statistics article
Int CountAll (LINE * & amp; The head)
{
The LINE * p=head;/* save list first address */
Int count=0;
Do/* calculate the total number of characters */
{
Count +=strlen (p - & gt; data);
}
While ((p=p - & gt; Next)!=NULL); Traverse the list/* */
return count;
}
STR/* statistics in the article the number of occurrences of */
Int FindString (LINE * & amp; The head, char * STR)
{
The LINE * p=head;
Int count=0;
int h=0;
Int len1=0;/* to save the current line to the total number of characters */
Int len2=strlen (STR);/* he calculated the length of the string */
int i,j,k;
Do
{
Len1=strlen (p - & gt; data);/* the current row number of characters */
for(i=0; i{
If (p - & gt; Data [I]==STR [0])
{
K=0;
for(j=0; JIf (p - & gt; Data [I + j]==STR [j]) k++;
If (k==len2) {count++; I=I + k - 1; }
}
}
}
While ((p=p - & gt; Next)!=NULL); Traverse the list/* */
return count;
}
/* delete specified string */
Void delstringword (char * s, char * STR)
/* * s for the input string, * STR to be deleted characters */
{
Char * p=STRSTR (s, STR);/* appear for the first time from the string s to find the STR position */
Char TMP [80].
Int len=strlen (s);
Int I=len - strlen (p);
Int j=I + strlen (STR);
Int count=0;
For (int m=0; MFor (int n=j; NTMP/count='\ 0';
Strcpy (s, TMP);/* */
new string}
Void DelString (LINE * & amp; The head, char * STR)
{
The LINE * p=head;
Do
{
If (STRSTR (p - & gt; The data, STR)!=NULL) delstringword (p - & gt; The data, STR);
}
While ((p=p - & gt; Next)!=NULL); Traverse the list/* */
}
/* to the screen output article */
Void the OutPut (LINE * & amp; The head)
{
The LINE * p=head;
Do
{
Printf (" % s \ n ", p - & gt; data);
}
While ((p=p - & gt; Next)!=NULL); Traverse the list/* */
}
Void main ()
{
The LINE * head;
Create (head);
Printf (" input article for: \ n ");
The OutPut (the head);
printf("\n");
Printf (" all alphabetic: % d \ n ", CountLetter (head));
Printf (" digital number: % d \ n ", CountNumber (head));
Printf (" number of Spaces: % d \ n ", CountSpace (head));
Printf (" the total number of words: % d \ n ", CountAll (head));
Char str1 [20], str2 [20];
printf("\n");
Printf (" please enter a string to statistics: ");
The scanf (" % s ", str1);
The number of occurrences of printf (" % s: % d \ n ", str1, FindString (head, str1));
printf("\n");
Printf (" please enter a string to delete: ");
The scanf (" % s ", str2);
DelString (head, str2);
Printf (" delete % s articles for: \ n ", str2);
The OutPut (the head);
}

CodePudding user response:

I suggest you to master the methods of debugging, F9 set breakpoints, F10 gradually tracking
You will find that your program is an error, because the head above address is empty, because you void the Create (LINE * head) not return a value, out of the function head life period is over, the solution: to redefine LINE * Create (LINE * head) function return head. The call will return the value assigned to your own definition LINE * head; It is ok to:
LINE * Create (LINE * head)
{
.
Return the head;
}

Void main ()
{
The LINE * head=the Create (head);
.
}

CodePudding user response:

Best stick error, convenient others to help you to check the wrong
  • Related