0
我在Xcode中引入了一個程序,但它在Visual Studio Express 2013中編譯得很好。 這實際上是一個例子,學校打出來並用於向我們展示令牌如何在C++中工作。我沒有寫這個。我得到的錯誤是在以下幾行:無法在Xcode中編譯C++程序,但它在Visual Studio Express 2013中編譯正常
while (tokenptr != '\0') // while tokenptr is not a null (then must be a token)
error is: "Comparison between pointer and integer('char' and 'int)"
tokenptr = strtok('\0', " ,.!?;:"); // get next token from null where left off
error is: "No matching function for call to 'strtok'"
我感覺問題是'\ 0',因爲程序突出顯示。 任何人都可以請幫我理解這個問題嗎?
感謝
/*
Exercise 3-12
This program will change an English phrase to Pig Latin
*/
#include<iostream>
#include<cstring>
using namespace std;
void plw(char []);
int main()
{
char sent[50], *tokenptr;
cout << "Enter a sentence: ";
cin.getline(sent, sizeof(sent), '\n'); // input up to size of cstring or until enter
tokenptr = strtok(sent, " ,.!?;:"); // get first token
while (tokenptr != '\0') // while tokenptr is not a null (then must be a token)
{
plw(tokenptr); // convert this cstring token to Pig Latin
cout << " "; // put space back in (old space was delimiter and removed)
tokenptr = strtok('\0', " ,.!?;:"); // get next token from null where left off
}
cout << endl;
}
// function to take each word token (or cstring or char array) and print as Pig Latin
void plw(char word[])
{
int x;
for (x = 1; x < strlen(word); x++)
cout << word[x];
cout << word[0] << "ay";
}
謝謝。我遇到的另一個問題發生了很多。 現在程序編譯好了,但我實際上並沒有輸入框輸入我的句子。我所做的是取代那個盒子,是一個帶有黑色背景的盒子(類似於輸入框),帶有綠色字母(lldb)。我相信這與調試器有關。在左邊是一個顯示帶有tokenptr變量的發送數組的框。發送char [50] tokenptr char *「」 左邊有一個綠色的L,我可以擴展每個。 非常感謝! – mercuryrsng 2014-09-20 18:02:23
@JustinPosner你應該問一個新的問題,以獲得一些可能經歷過同樣問題的人的注意。 – dasblinkenlight 2014-09-20 18:41:12