atoi

    2热度

    1回答

    如何使用从* argv的[]一个八进制的字符串类似: open("outfile",O_CREAT | O_RDWR,0777); 0777意味着八进制数的权限。 我的代码: int arC = atoi(argv[optind]); printf("argv optind %s after atoi %d\n",argv[optind],arC); int test =des2=open

    0热度

    1回答

    我尝试过atoi,strol和stoi,但是他们都没有为我工作。我甚至试图从我听到的字符中减去'0'应该工作,但也抛出了一个错误。 atoi给我一个分段错误,strol不会编译,stoi给我一个std逻辑错误。这里是我的整个计划截至目前: #include <iostream> #include <string> #include <stdlib.h> using namespace st

    0热度

    2回答

    我有一个非常大的字符串,其中包含2位数字和它们之间的空间按顺序xx xx xx ...等'。 我试图将每个数字转换为int并将其存储在20x20的int数组中。 对于这个任务,我使用memcpy来复制字符串的前2位数字,atoi从char中将int转换为int,而我写的内部函数将字符串“左”移动一圈。 它可以正常工作,例如60号码,然后在程序结束时出错号码。 这是代码: #include <std

    1热度

    2回答

    我写了这段代码来获得一个反向形式的数字。但是,如果我使用任何负面的输入,它显示正反向数字。 C中的atoi函数可以处理否定吗? #include<stdio.h> #include<string.h> #include<stdlib.h> int main(void){ char ar[40]; char ar2[40]; int fnum; scanf("%s",ar); for

    2热度

    2回答

    如果optarg(来自Getop库的标志-s之后的参数)不是数字,我希望打印出错误消息并终止程序,如果它是一个数字,大小需要设置为optarg。我遇到的问题是,像-s r这样的命令会输出错误信息,-s 2也会,这意味着它将2解释为字符串。 调试与-s 2 #1 printf("%d",atoi(optarg)); #2 printf("%d",isdigit(atoi(optarg)));

    1热度

    1回答

    尝试将一些逗号分隔值从字符串中加在一起。我觉得我需要删除逗号。这是stringstream的情况吗? string str = "4, 3, 2" //Get individual numbers //Add them together //output the sum. Prints 9

    -1热度

    1回答

    因此,我不确定是否应该尝试将argv [1]转换为int,或者是否可以将其保留为char。但是我很难让argv按照我想要的方式行事。 我的终端输入将看起来像这样: ./a.out a 其中的argv [1]可以是一个 '一' 或 'd'。 问题:试图通过传递给它当if语句如: int main(int argc, char *argv[]) { char *letter;

    -4热度

    2回答

    main(int argc,char **argv) { int n1,n2,n3; if(argc!=4) { printf("Usage:./cal 10+20\n"); return; } n1=atoi(argv[1]); n2=atoi(argv[3]); switch(argv[2][0]) { case '+': n3=n1+n2; print

    0热度

    3回答

    我想的整数转换为像字符串: int a = 12345 覆羽到 char b[6] = "12345" 基本上是一个字符串转换为整数的函数的atoi的相反。

    0热度

    3回答

    我正在学习C,我试图找出如何用char数组创建数据库。我知道atoi使用字符串,但我不明白字符串和字符数组声明之间的区别(我明白字符串也有'/ 0'字符)。 它在该行int w = LoggersID[j]; #include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> int main()