`
jubincn
  • 浏览: 248910 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
文章分类
社区版块
存档分类
最新评论

GCC中gets()/fges()读入输入的问题解决 -- 清理stdin缓存

 
阅读更多

这几天一直被一个bug折磨,最终发现是stdin缓存了‘\n’,因此fgets()函数无法正常执行,解决的方法是在调用fgets()之前将缓存清空。VC中可以使用fflush(stdin)的方法,但在gcc中,fflush(stdin)的作用并不是清空stdin缓存,因此需要我们手动来做,代码如下:

代码说明:

这段代码的目的是读入矩阵的行、列数,然后让用户一次性输入整个矩阵。问题出在get_row_col()函数中的scanf上,解决方式是在fgets中加入清除缓存的循环。




分享到:
评论

相关推荐

    mtk 6572 modem tools tools/GCC/4.6.2/linux/bin/arm-none-eabi-gcc

    解决mtk6572平台modem编译错误! Please install the GCC Cross-Compiler on correct path: tools/GCC/4.6.2/linux/bin/arm-none-eabi-gcc

    MTK 6737 Modem tools tools/GCC/4.6.2/linux/bin/arm-none-eabi-gcc

    解决mtk6737平台modem编译错误! Please install the GCC Cross-Compiler on correct path: tools/GCC/4.6.2/linux/bin/arm-none-eabi-gcc

    cc1-放入/usr/libexec/gcc/x86_64-redhat-linux/4.4.4/内

    gcc: error trying to exec 'cc1': execvp: No such file or directory

    arm-linux-gnueabi-5.4.0.tar

    使用arm-linux-gcc 出现一下问题: rm-linux-gcc src/Output.c -o src/Output.o -I./inc -c /usr/local/arm/5.4.0/usr/bin/../libexec/gcc/arm-none-linux-gnueabi/5.4.0/cc1: error while loading shared libraries...

    CentOS7 nginx离线安装gcc/pcre-devel/openssl-devel/zlib-devel包

    在Linux系统中,尤其是服务器环境,离线安装软件包是非常常见的需求。本教程将详细介绍如何在CentOS 7上离线安装GCC、PCRE-devel、OpenSSL-devel和Zlib-devel这些重要的开发工具包,这些都是构建和编译Nginx web...

    arm-2014.05-29-arm-none-linux-gnueabi

    Configured with: /scratch/maciej/arm-linux-2014.05-rel/src/gcc-4.8-2014.05/configure --build=i686-pc-linux-gnu --host=i686-mingw32 --target=arm-none-linux-gnueabi ...... Thread model: posix gcc ...

    winlibs gcc/g++编译器 mingw64 10.0.0-r4

    但是,在windows环境下使用gcc/g++编译器总会存在这样那样的问题,比如使用cin或者scanf输入中文,输出就变成了乱码等问题,本资源版本是由由WinLibs维护的开源版本winlibs-x86_64-posix-seh-gcc-12.2.0-llvm-15.0.7...

    gcc升级到4.8.5

    tar xvf /root/gcc-src/mpfr-3.1.4.tar.gz -C /root/gcc-4.8.5/ 或者 tar xvf /root/gcc-src/mpfr-3.1.4.tar.bz2 -C gcc-4.8.5/ mv /root/gcc-4.8.5/cloog-0.18.4 /root/gcc-4.8.5/cloog mv /root/gcc-4.8.5/gmp-...

    arm-linux-gcc交叉编译器 4.3.2 part2

    本文件为arm-linux-gcc-4.3.2.tgz的part2 arm-linux-gcc-4.3.2.tgz.ab,需要与arm-linux-gcc-4.3.2.tgz的part1 arm-linux-gcc-4.3.2.tgz.aa 合并成一个文件arm-linux-gcc-4.3.2.tgz 安装方法: 0. cat arm-linux-gcc-...

    gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12.txt

    需要在系统环境变量下,即/etc目录下在bush.bushrc文件里面的最后一行,添加export PATH=$PATH:/home/zhy/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin,这个需要根据自己目录存放的位置...

    arm-linux-gcc-4.3.2(交叉编译器)

    Configured with: /opt/crosstool/crosstool-0.28/build/arm-linux/gcc-3.4.1-glibc-2.3.2/gcc-3.4.1/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/opt/crosstool/arm-linux/gcc-3.4.1-...

    经典的编译器gcc2.95.3安装文件(已编译)

    sudo ln -s /usr/local/gcc-2.95/lib/libstdc++-3-libc6.3-2-2.10.0.so /usr/lib/libstdc++-3-libc6.3-2-2.10.0.so sudo ln -s /usr/lib/222libstdc++-3-libc6.3-2-2.10.0.so /usr/lib/libstdc++-libc6.3-2.so.3 ...

    gcc-arm-none-eabi-7-2018-q2-update-win32.zip

    It includes the GNU Compiler (GCC) and is available free of charge directly from Arm for embedded software development on Windows, Linux and Mac OS X operating systems. Follow the links on this page ...

    arm-linux-gcc-3.4.1(交叉编译器)

    Configured with: /opt/crosstool/crosstool-0.28/build/arm-linux/gcc-3.4.1-glibc-2.3.2/gcc-3.4.1/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/opt/crosstool/arm-linux/gcc-3.4.1-...

    gcc-arm-none-eabi-9-2019-q4-major-win32.zip

    标题中的"gcc-arm-none-eabi-9-2019-q4-major-win32.zip"是一个针对Windows操作系统的GCC交叉编译工具链压缩包。这个工具链是专门为ARM架构的微控制器和嵌入式系统设计的,使得开发者可以在运行Windows的个人电脑上...

    gcc/pcre-devel/openssl-devel/zlib-devel negix centos7依赖rpm

    标题中的“gcc/pcre-devel/openssl-devel/zlib-devel negix centos7依赖rpm”揭示了几个关键的组件,它们是Negix在CentOS 7环境下运行所必需的开发库。让我们详细了解一下这些组件及其重要性。 1. **Negix**: Negix...

    gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux.7z

    交叉编译工具:gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux.tar.bz2 解压命令:tar jxvf gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux.tar.bz2

    离线安装gcc(版本:7.2.0)

    ./configure --prefix=/usr/local/gcc-7.2.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-3.1.6 --...

    gcc4.8.5离线安装rpm包含依赖

    tar -xvf gcc-rpms.tar.gz ``` ## rpm安装gcc ```bash rpm -Uvh *.rpm --nodeps --force ``` ### 验证 ```bash gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-...

    CentOS7 nginx离线安装gcc/pcre-devel/openssl-devel/zlib-devel以及其他包

    gcc-4.8.5-36.el7.x86_64.rpm glibc-devel-2.17-260.el7.x86_64 openssl-1.0.2k-16.el7.x86_64 openssl-devel-1.0.2k-16.el7.x86_64 openssl-libs-1.0.2k-16.el7.x86_64 pcre-devel-8.32-17.el7.x86_64 zlib-1.2.7-...

Global site tag (gtag.js) - Google Analytics