הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   [C] בעיה בתוכנית (https://hosts.co.il/forums/showthread.php?t=45001)

mayden 07-05-07 14:00

[C] בעיה בתוכנית
 
יש לי את התוכנית הבאה:
קוד:

#include <stdio.h>
#include <string.h>

typedef char string;

void main () {
        string st1="ABCBD";
        string st2="CEB";
        string st3="";
        string sth="";
        int pl=0;
        char tav;
        while(strlen(st1)>0) {
                tav = st1[(strlen(st1)-1];
                strncpy(sth,st1,strlen(st)-1);
                if((strchr(st2,tav)!=null && (strchr(sth,tav) == null)
                {
                        st3[pl] = tav;
                        pl++;
                }
                strcpy(st1,sth);
        }
        st3[pl]='\0';
        puts(st3);

}

וכשאני מנסה להריץ אותה, כותב לי:
קוד:

--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\C\Cpp1.cpp(7) : error C2440: 'initializing' : cannot convert from 'char [6]' to 'char'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\C\Cpp1.cpp(8) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'char'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\C\Cpp1.cpp(9) : error C2440: 'initializing' : cannot convert from 'char [1]' to 'char'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\C\Cpp1.cpp(10) : error C2440: 'initializing' : cannot convert from 'char [1]' to 'char'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\C\Cpp1.cpp(14) : error C2664: 'strlen' : cannot convert parameter 1 from 'char' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\C\Cpp1.cpp(14) : fatal error C1903: unable to recover from previous error(s); stopping compilation

אני משתמש בMicrosoft Visual C++

תודה.

Meir 07-05-07 14:08

אתה צריך להגדיר את אורך בstring כאן:

קוד:

typedef char string[NUMBER];

mayden 07-05-07 14:42

תודה,
הסתדרתי בכל אופן.


כל הזמנים הם GMT +2. הזמן כעת הוא 00:58.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ