Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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 - Fatal编程技术网

从随机输入语言C中提取字母

从随机输入语言C中提取字母,c,C,我是新来的。我开始从事软件工程,对C语言一无所知。我向队列添加了一部分,但是我不能分离外来值​​进入。你能帮我吗 我想执行图片中的步骤 例如: 输入:E)(=89y-/u665%p 输出:EYUP 我的代码 #include <stdio.h> #include<string.h> #include <stdlib.h> #define max 5 int insq(char queue[max][80], int *rear, char data[80])

我是新来的。我开始从事软件工程,对C语言一无所知。我向队列添加了一部分,但是我不能分离外来值​​进入。你能帮我吗

我想执行图片中的步骤

例如:

输入:E)(=89y-/u665%p
输出:EYUP

我的代码

#include <stdio.h>
#include<string.h>
#include <stdlib.h>
#define max 5
int insq(char queue[max][80], int *rear, char data[80])
{
    if (*rear == max -1)
        return(-1);
    else
    {
        *rear = *rear + 1;
        strcpy(queue[*rear], data);
        return(1);
     }
}
int delq(char queue[max][80], int *front, int *rear, char data[80])
{
    if(*front == *rear)
        return(-1);
    else
    {
        (*front)++;
        strcpy(data, queue[*front]);
        return(1);
     }
 }
 int main()
 {
     char queue[max][80], data[80];
     int front, rear, reply;
     int ch;
     front = rear = -1; //... Initialize a Queue
     printf("------------------------------\n");
     printf("\tMenu");
     printf("\n------------------------------");
     printf("\n 1. Insert String in a Queue");
     printf("\n 2. Delete String from a Queue");
     printf("\n 3. Exit");
     printf("\n------------------------------\n");
     while(1)
     {
           printf("Choose operation : ");
           scanf("%d", &ch);
           switch(ch)
           {
              case 1 : // insert
                    printf("\nEnter Something : ");
                    scanf("%s",data);
                    reply = insq(queue, &rear, data);
                    if(reply == -1 )
                          printf("\nQueue is Full \n");
                    else
                          printf("\n'%s' is inserted in queue.\n\n",data);
                    break;
              case 2 : // delete
                    reply = delq(queue, &front, &rear, data);
                    if( reply == -1 )
                          printf("\nQueue is Empty \n");
                    else
                          printf("\nDeleted String from Queue is : %s\n", data);
                          printf("\n");
                    break;
              case 3 : exit(0);
              default: printf("Invalid operation \n");
        }
    }
    return 0;
}
#包括
#包括
#包括
#定义最大值5
int insq(字符队列[max][80],int*rear,字符数据[80])
{
如果(*后==最大值-1)
返回(-1);
其他的
{
*后部=*后部+1;
strcpy(队列[*后方],数据);
申报表(1);
}
}
int-delq(字符队列[max][80],int*前,int*后,字符数据[80])
{
如果(*前==*后)
返回(-1);
其他的
{
(*前)+;
strcpy(数据,队列[*前端]);
申报表(1);
}
}
int main()
{
字符队列[max][80],数据[80];
int前,后,回复;
int-ch;
前=后=-1;/…初始化队列
printf(“--------------------------------------\n”);
printf(“\tMenu”);
printf(“\n-----------------------------”);
printf(“\n 1.在队列中插入字符串”);
printf(“\n 2.从队列中删除字符串”);
printf(“\n 3.退出”);
printf(“\n--------------------------------------\n”);
而(1)
{
printf(“选择操作:”);
scanf(“%d”和“ch”);
开关(ch)
{
案例1://插入
printf(“\n输入某物:”);
扫描频率(“%s”,数据);
回复=insq(队列和后部,数据);
如果(回复==-1)
printf(“\n队列已满\n”);
其他的
printf(“\n'%s'已插入队列。\n\n”,数据);
打破
案例2://删除
回复=delq(队列、前部和后部、数据);
如果(回复==-1)
printf(“\n队列为空\n”);
其他的
printf(“\n从队列中删除的字符串为:%s\n”,数据);
printf(“\n”);
打破
案例3:退出(0);
默认值:printf(“无效操作\n”);
}
}
返回0;
}

您必须逐个字符解析字符串。 测试它是否是一个带有
isalpha
的字符,然后执行
toupper
并将其放到缓冲区
out
。如果不测试空白字符并将其复制为空字符,最后只需跳过字符即可

不要忘记添加最后的
\0

/!\n如果缺少,则进行测试,以检查是否溢出
out

#include <stdio.h>
#include <ctype.h>

int main() {
    const char *p = "E)(=89y-/u665%P";
    char out[80];
    char *q = out;

    while (*p) {
        if (isalpha(*p)) {
            *q++ = toupper(*p++);
            continue;
        } else if (isblank(*p)) {
            *q++ = *p++;
            continue;
        }
        p++;
    }
    *q= '\0';
    printf("%s\n", out);

    return 0;
}
#包括
#包括
int main(){
常量char*p=“E”(=89y-/u665%p);
字符输出[80];
char*q=out;
而(*p){
如果(isalpha(*p)){
*q++=toupper(*p++);
继续;
}else if(为空(*p)){
*q++=*p++;
继续;
}
p++;
}
*q='\0';
printf(“%s\n”,out);
返回0;
}

您有输入输出
“EYUP”

请说明有关代码的实际错误、错误行为或问题。如果代码未按您的预期工作,则需要对其进行调试。请使用调试器逐步调试代码。..Does
If((data[]>='a'&&data[]@风向标你能帮我找到所有的代码吗?看看链接的伪代码图像,你可能对函数族
isalpha()
isspace()
ispunct()
等感兴趣。我不明白你想用
queue
做什么。这是一个由5个80个字符组成的数组。我无法运行此代码。[错误]参数“p”为initialized@EyüpŞirin我已经添加了完整的编译代码。你太棒了,非常感谢。我如何才能让这个混合输入提示用户?@rel