c - 预处理器指令不起作用

标签 c

我制作了一个程序,它通过预处理器指令删除空格并使字符串大写。它不会更改为大写

#include <stdio.h>
#include <conio.h>
# define TOUPPER(x) (x-32)
void main(void)
{
    int i,j;
    char str[100],*p;
    clrscr();
    printf("Enter the string:\n");
    gets(str);
    for(i=0;    ;i++)
    {
        if(str[i]=='\0')
        break;
        if(str[i]==' ')
        {
            for(j=i;    ;j++)
            {
             str[j]=str[j+1];
             if(str[j]=='\0')
             break;
            }
         }
         if(str[i]<='a'||str[i]>='z')
         {
            *p=str[i];
            TOUPPER('p');

         }


        }
        puts(str);
    getch();
}

最佳答案

你的 TOUPPER('p') 完全按照它应该做的去做,什么也没做。您从 'p' 的数值中减去 32,然后将其丢弃。请注意,我指的是“p”字符,而不是 p 指针。

关于c - 预处理器指令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3250317/

相关文章:

c - C语言中如何按属性对对象进行排序

c - 检索 double 的小数部分

c - UNIX fork() 之后的 printf()

c++ - 在 netbeans 的项目中编译单个文件

c - C 代码中求和结果错误

c - 将函数放入 avr 中跳过字符

c - 在 c 中使用 printf 打印常数指数值

printf 中的 C 段错误 - dl-lookup.c

c - 无穷大计算器

C程序: multi-word guessing game conversion error