Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何打印数组中的所有单词并在同一函数中拆分它们_C_Pointers - Fatal编程技术网

C 如何打印数组中的所有单词并在同一函数中拆分它们

C 如何打印数组中的所有单词并在同一函数中拆分它们,c,pointers,C,Pointers,我有一个这样的程序来打印所有的单词 单词\u数组,用分隔符分隔单词,在 最后一句话 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<unistd.h> #include<ctype.h> #include<assert.h> void capitalize(char * lowercase) { while (*lowercase) {

我有一个这样的程序来打印所有的单词 单词\u数组,用分隔符分隔单词,在 最后一句话

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<ctype.h>
#include<assert.h>
void capitalize(char * lowercase) {
    while (*lowercase) {
        *lowercase = toupper(*lowercase) ;
        lowercase++ ;
    }
    return ;
}

void capitalize_all(char ** string) {
    while (*string) {
        capitalize(*string) ;
        string++ ;
    }
    return ;
}
void print_everything(char ** string, char * delimiter) {
    scanf("string =",string) ;
    for(int i=0; sp[i]!='\0'; i++)
   {
      printf("%c", string[i]);

      if(*string[i]==' ')
      {
         printf("\n");
      }
   }
    return ;
}
int main(int argc, char * argv[]) {
    int char ;
    char ** the_word_array ;
    char ** pp ;
    int i ;
    while ((char = getopt(argc, argv, "")) != -1) {
        switch(char) {
            break ;
        default:
                printf("%s\n", USAGE_MESSAGE) ;
                return 0 ;
        }
    }
    argc -= optind; // these are globals defined in the getopt code
    argv += optind;

    the_word_array = (char **) malloc((sizeof(void *)*(argc+1))) ;
    for (i=0;i<argc;i++) {
        the_word_array[i] = argv[i] ;
    }
    the_word_array[argc] = NULL ;
    pp = the_word_array ;
    capitalize_all(pp) ;
    print_all(word_array," ") ;
    return 0 ;
}

#包括
#包括
#包括
#包括
#包括
#包括
大写无效(字符*小写){
while(*小写){
*小写=大写(*小写);
小写++;
}
返回;
}
全部大写无效(字符**字符串){
while(*字符串){
大写(*字符串);
字符串++;
}
返回;
}
无效打印所有内容(字符**字符串,字符*分隔符){
scanf(“string=”,string);
对于(int i=0;sp[i]!='\0';i++)
{
printf(“%c”,字符串[i]);
如果(*字符串[i]='')
{
printf(“\n”);
}
}
返回;
}
int main(int argc,char*argv[]){
int字符;
字符**单词数组;
炭**pp;
int i;
while((char=getopt(argc,argv,“”)!=-1){
开关(字符){
打破
违约:
printf(“%s\n”,用法\u消息);
返回0;
}
}
argc-=optind;//这些是在getopt代码中定义的全局变量
argv+=optind;
单词数组=(char**)malloc((sizeof(void*)*(argc+1));

对于(i=0;我必须使用
strtok
。我知道,但是如果我们正确使用它,会出现指针问题。是的。那么问题出在哪里?尝试一下,如果它确实有问题,请在这里询问。如果我们在上面的链接中使用定界,程序将不会运行,我将出现如下错误:错误:从不兼容的指针传递'strtok'的参数1类型[-Wincompatible pointer types]|来自不兼容指针类型的
是一个警告而非错误!您必须在
strtok
之后检查指针是否不为null。当然,您必须将char*传递给
strtok