字符数组

This commit is contained in:
flykhan 2023-06-02 03:05:10 +08:00
parent edc6966b9d
commit 4cbb3e3d78
No known key found for this signature in database
4 changed files with 95 additions and 1 deletions

View File

@ -11,7 +11,7 @@ int main(int argc, char *argv[])
int i; int i;
for(i = 0; i< sizeof(a) / sizeof(int);i++) for(i = 0; i< sizeof(a) / sizeof(int);i++)
{ {
printf("a[%d] = %d\n",i,a[i]); printf("a[%d] = %d\n",i,a[i]);
} }
printf("************************\n"); printf("************************\n");

73
2_lesson/05_array_char/.gitignore vendored Normal file
View File

@ -0,0 +1,73 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe

View File

@ -0,0 +1,6 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
// 定义一个字符数组通过scanf函数输入字符串并输出结果
// 通过赋值""这样的方式可以清除字符数组中的垃圾字符,让每一个元素都是\0
char ch[32] = "";
// 数组名就是当前数组的首地址所以scanf的第二个参数直接传数组名即可
scanf("%s", ch);
printf("ch = %s\n", ch);
return 0;
}