我的回文计划是一个例外吗?

时间:2014-09-09 02:33:12

标签: c++ c

我正试图在Palindrome的程序下面运行,但它正在给我Exception error,请帮忙吗?我正在使用Visual studio 2013

#include<iostream>

int main(){
    char a[100], b[100];

    std::cout << "This is a program to check palindrome or not." << std::endl;
    std::cout << "Enter your string:\n" << std::endl;
    gets(a);

    /*Here string does copy..*/
    strcpy(a, b);

    /*Here string does reverse..*/
    strrev(b);

    /*Here string does compare*/
    if (strcmp(a, b) == 0){
        std::cout << "Congrats, It's palindrome!" << std::endl;
    }
    else{
        std::cout << "Sorry BOSS but this is not a palindrome." << std::endl;
    }
    return 0;
}

帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

char *strcpy(char *dest, const char *src);

目的地是第一个参数,源是第二个参数。将复制命令更改为

strcpy(b, a);