C语言输入函数三种形式

#include<iostream>

using namespace std;

#include<stdio.h>

#include<conio.h>

/*

从标准输入读取一段整数,并将这段整数存储在一个动态分配的数组中,

数组的第一个元素是整数的个数,后面依次是这些整数。

1.getchar int getchar(void) 输入形式字符 输出int,适合不定长字符串

while((c = getchar()) != '\n')

2.scanf int scanf("",&) 返回读取成功的个数,int

while(1 == scanf("%d",&a))

3.gets char* gets(char*) 输入char 输出char 适合定长字符串 遇空格截断

1 2 3 4 5 6 k

6 1 2 3 4 5 6

*/

#define N 10

#if 0

void main()

{

int* p = NULL;

int size = N;

p = (int*)malloc(sizeof(int) * (size + 1));

int a;

int count = 0;

// 1 2 3 4 5 6 7 8 9 10 11

while (1 == scanf_s("%d", &a))

{

count++;

if (count > size)

{

size = size + N;

p = (int*)realloc(p, sizeof(int) * (size + 1));

//

}

p[count] = a;

}

//...

p = (int*)realloc(p, sizeof(int) * (count + 1));

p[0] = count;

for (int i = 0; i <= count; ++i)

{

printf("%d ", p[i]);

}

printf("\n");

free(p);

p = NULL;

}

#endif

#if 0

void main()

{

char str1[] = "abc";

char str2[] = "abc";

const char str3[] = "abc";

const char str4[] = "abc";

const char* str5 = "abc";

const char* str6 = "abc";

//char* str7 = "abc";

//char* str8 = "abc";

printf("%d\n", str1 == str2);

printf("%d\n", str3 == str4);

printf("%d\n", str5 == str6);

//printf("%d\n", str7 == str8);

}

#endif

#if 0

union X

{

int x;

char y[4];

};

void main()

{

union X a;

a.x = 0x11223344;

printf("%x\n", a.y[3]);

}

#endif

#if 0

void main()

{

int a = 3, b = 4, c = 5;

while (a < b < c)//a<b&&b<c

{

int t = a;

a = b;

b = t;

c--;

}//434 343 432 341

printf("%d,%d,%d\n", a, b, c);

}

#endif

//a >=-1e-6 && a <=1e-6

#if 0

void main()

{

int a = 10;

while (a < a + 10)

a++;

printf("大家好\n");

}

#endif

void fn()

{

static int aa = 10;

aa++;

}

void main()

{

//extern int a;

//printf("a = %d\n", a);

fn();

fn();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C语言中,main函数输入参数argv是一个字符串数组,用来存储运行程序时传递给main函数的参数。每个参数都以字符串的形式存储在argv数组中。argc是一个整数,表示传递给main函数的参数个数。通过argc和argv,我们可以在程序中获取和处理命令行输入的参数。例如,可以使用循环遍历argv数组来逐个打印出所有的参数。下面是一个示例程序: ```c #include <stdio.h> int main(int argc, char *argv\[\]) { int i; for (i = 0; i < argc; i++) { printf("Argument %d is %s.\n", i, argv\[i\]); } return 0; } ``` 在上述程序中,通过循环遍历argv数组,可以打印出每个参数的索引和对应的字符串值。例如,如果在命令行中执行程序时输入了两个参数,那么程序会输出: ``` Argument 0 is 程序名. Argument 1 is 第一个参数. ``` 其中,程序名是argv\[0\],第一个参数是argv\[1\]。依此类推,可以根据argc和argv来处理不同的命令行参数。 #### 引用[.reference_title] - *1* *3* [C语言main函数argc argv介绍](https://blog.csdn.net/persever/article/details/77446618)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [【C语言】main函数的argc、argv传参](https://blog.csdn.net/weixin_43955214/article/details/104322230)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值