Прога должна считать данные, строки, из командной строки, так мы создадим связный список, а потом один из них присоединяем к другому. Я уверен, что косяки в в функции
C |
1
| void read(struct symbols *axe, char *data) // функция должна заносить данные в связный список |
|
А вот собственно и сама программа
C |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 50
struct symbols{
char letter[N];
struct symbols *nextPtr;
};
void read(struct symbols*,char *);
void concatenate(struct symbols * , struct symbols *);
int main()
{
struct symbols *startPtr1 = NULL;
struct symbols *startPtr2 = NULL;
struct symbols *previousPtr, *currentPtr;
char data[N];
int i;
for(i=0;i<2;i++){
gets(data);
read(startPtr1, data);
}
for(i=0;i<2;i++){
gets(data);
read(startPtr2, data);
}
concatenate(startPtr1,startPtr2);
previousPtr = NULL;
currentPtr = startPtr1;
while(currentPtr != NULL){
printf("%s",currentPtr->letter);
previousPtr = currentPtr; // переход
currentPtr = currentPtr->nextPtr; // к следующему
}
return 0;
}
void read(struct symbols *axe, char *data) // функция должна заносить данные в связный список
{
struct symbols *newPtr,*previousPtr, *currentPtr;
newPtr = (struct symbols*) malloc(sizeof(struct symbols));
if(newPtr != NULL){ // проверка памяти
strcpy(newPtr->letter,data); // считывание строки
newPtr->nextPtr=NULL; // обнуляем указатель на конец структуры
previousPtr = NULL;
currentPtr = axe;
while(currentPtr != NULL){
previousPtr = currentPtr; // переход
currentPtr = currentPtr->nextPtr; // к следующему
}
if (previousPtr == NULL){
newPtr->nextPtr = axe;
axe = newPtr;
}
else {
previousPtr->nextPtr =newPtr;
newPtr->nextPtr = currentPtr;
}
}
}
void concatenate(struct symbols *ptr1 , struct symbols *ptr2)
{
struct symbols *previousPtr, *currentPtr;
previousPtr = NULL;
currentPtr = ptr1;
while(currentPtr != NULL){
previousPtr = currentPtr; // переход
currentPtr = currentPtr->nextPtr; // к следующему
}
currentPtr=ptr2;
} |
|
Заранее благодарен.
Добавлено через 56 минут
главный косяк, по мне так , это на 60-69 строках, проверка условаия
C |
1
2
3
4
| if (previousPtr == NULL){
newPtr->nextPtr = axe;
axe = newPtr;
} |
|
почему то всегда верная
Добавлено через 2 часа 9 минут
блин перепесал обе фунции, таже проблема (
C |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 50
struct symbols{
char letter[N];
struct symbols *nextPtr;
};
void read(struct symbols*,char *);
void concatenate(struct symbols * , struct symbols *);
int main()
{
struct symbols *startPtr1 = NULL;
struct symbols *startPtr2 = NULL;
struct symbols *currentPtr;
char data[N];
int i;
for(i=0;i<2;i++){
gets(data);
read(startPtr1, data);
}
for(i=0;i<2;i++){
gets(data);
read(startPtr2, data);
}
concatenate(startPtr1,startPtr2);
currentPtr = startPtr1;
while(currentPtr != NULL){
printf("%s",currentPtr->letter);
currentPtr = currentPtr->nextPtr;
}
return 0;
}
void read(struct symbols *axe, char *data) // функция должна заносить данные в связный список
{
struct symbols *current=axe;
while(current!=0)
current=current->nextPtr;
if(current==NULL){
struct symbols *res;
res = (struct symbols*)malloc(sizeof(struct symbols));
strcpy(res->letter, data);
res->nextPtr=axe;
axe=res;
}
}
void concatenate(struct symbols *ptr1 , struct symbols *ptr2)
{
struct symbols *currentPtr=ptr1;
while(currentPtr != NULL)
currentPtr = currentPtr->nextPtr;
currentPtr=ptr2;
} |
|