在C中,我正在做一個標記器。我就麻煩了,因爲我發現,如果我鍵入:printf刪除內容 r在C
printf ("String of text\r");
所有被'\r'
之前所著不打印。
所以,如果我要來標記"String of text\r"
,最後令牌應該"Text"
,不,它" ext"
有人知道爲什麼嗎?
編輯:此代碼。如果我打印ARGS [0],ARGS [1] ...和Im炭[] STR = 「卡德納德texto \ R」
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int
detectpattern(char target)
{
int patternsize;
int contador;
int found;
char pattern[] = {'\t', '\r', ' ', '\n', ' '};
patternsize = sizeof(pattern)/sizeof(char);
contador = 1;
while (contador <= patternsize) {
if (pattern[contador] == target) {
found = 1;
break;
}
else {
found = 0;
}
contador++;
}
return found;
}
void
ispattern(char *str, int *inword){
if (*inword != 0) {
*inword = 0;
*str = '\0';
}
}
void
isword(char *str, int *inword, char **args, int *words){
if (*inword == 0) {
*inword = 1;
args[*words] = str;
*words = *words + 1;
}
}
int
mytokenize(char *str, char **args, int maxargs) {
int i;
int intword;
int intwords;
int * inword = &intword;
int * words = &intwords;
intword = 0;
intwords = 0;
i = 0;
if (!str[i]) {
printf("String no válido");
exit(0);
}
while (str[i] != '\0') {
if (detectpattern(str[i])) {
ispattern(&str[i], inword);
} else {
isword(&str[i], inword, args, words);
}
if (*words == maxargs) {
break;
}
i++;
}
return *words;
}
enum{
maxargs = 2,
};
int
main(int argc, char *argv[]){
char str[] = "cadena de texto";
char *strptr = &str[0];
char *array_punteros[maxargs];
mytokenize(strptr, array_punteros, maxargs);
exit(0);
}
請發佈標記器代碼。 –
這似乎是2個不同的問題?你想知道打印字符串還是標記字符串? –
另外,'\ r'是回車,也許看看[this](http://stackoverflow.com/questions/9253250/need-help-understanding-how-nb-and-rill-render- printf-output) –