小编Pau*_*ate的帖子

十六进制格式的无符号长整型打印

我想打印出unsigned long long这样的:

  printf("Hex add is: 0x%ux ", hexAdd);
Run Code Online (Sandbox Code Playgroud)

但我得到了类型转换错误,因为我有一个unsigned long long.

c printf integer

43
推荐指数
2
解决办法
8万
查看次数

C字符串函数调用,按值传递还是引用?

我无法弄清楚发生了什么,我认为C是值得传递但是这个简单的功能让我对它的工作方式感到困惑.

 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>

 void testFunc(char string1[])
 {
   char string2[50] = "the end";
   strcat(string1, string2);
   printf("in func %s \n", string1);
 }

 void main()
 {
    char string1[50] = "the start";
    printf("%IN MAIN %s \n", string1);
    testFunc(string1);
    printf("IN MAIN %s \n", string1);
 }
Run Code Online (Sandbox Code Playgroud)

令人困惑的输出是:

在主要开始

在FUNC开始

在主要开始

那么这里发生了什么?C是否真的传递了char数组的地址而不是复制它的值?我以为这就是char*表现不怎么样char[]

c string parameter-passing

3
推荐指数
2
解决办法
9817
查看次数

从文件中进行十六进制转换

我的代码出了什么问题?我试图逐行读取文件并将0x"十六进制数"形式的数字转换为整数.它只返回1行然后结束,我的输入是这样的

0x9C40

0x3B9AC9FF

0x754893gf

0x754893gf

0x754893gf

0x754893gf

  #include <stdio.h>
#include <stdlib.h>


 #include <stdio.h>

 #define MAXCHAR 1000
 int main() {
     FILE *fp;
    char str[MAXCHAR];
    char* filename = "C:\\test.txt";
    int number;

    fp = fopen(filename, "r");
   if (fp == NULL){
      printf("Could not open file %s",filename);
      return 1;
     }
   while (fgets(str, MAXCHAR, fp) != NULL)
       number = (int)strtol(str, NULL, 0);
    printf("%d\n", number);
   fclose(fp);
    return 0;
    }
Run Code Online (Sandbox Code Playgroud)

c

1
推荐指数
1
解决办法
70
查看次数

标签 统计

c ×3

integer ×1

parameter-passing ×1

printf ×1

string ×1