小编NUO*_*NUO的帖子

如何在带有iso_8859-1的C程序中输出度数符号?

我查了iso_8859-1的手册,找到了度数符号:

\n\n
Oct   Dec   Hex   Char   Description\n260   176   B0     \xc2\xb0     DEGREE SIGN\n
Run Code Online (Sandbox Code Playgroud)\n\n

代码:

\n\n
int main( int argc, char *argv[])\n{\n    char chr = 176; //stores the extended ASCII of a symbol\n    printf("Character with an ascii code of 251: %c \\n", chr);\n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

但它打印出来的是?.

\n\n

如何在 C 程序中输出学位符号?我需要包含一些文件吗?

\n

c iso-8859-1

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

生成c中的随机浮点数[0,1]

当我使用rand()和srand()在[0,1]中生成随机数时,它给出了我的数字:0.70324,0.70328,0.70321 ......

它们仅在最后一位或两位数上有所不同,而我的意图是获得随机浮点数,如0.1,0.7,0.3 ....

我怎么能得到这样的随机浮点数而不是在最后一位数上有所不同?

这是我的代码:

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

int main(){
    int i;
    float randomNum;
    for (  i=0; i<10; i++){
        srand((unsigned int)time(NULL));
        randomNum = ((float)rand())/RAND_MAX;
        printf("%f\n",randomNum);
     }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c random

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

如何继续使用malloc?

我有一个存储整数序列的文件.总的整数是未知的,所以如果我从文件中读取一个整数,我继续使用malloc()来应用新的内存.我不知道我是否可以继续询问内存并在数组末尾添加它们.Xcode一直警告我malloc()行中的'EXC_BAD_EXCESS'.如果我继续从文件中读取整数,我怎么能这样做?

int main()
{
    //1.read from file
    int *a = NULL;
    int size=0;
    //char ch;
    FILE *in;

    //open file
    if ( (in=fopen("/Users/NUO/Desktop/in.text","r")) == NULL){
        printf("cannot open input file\n");
        exit(0);    //if file open fail, stop the program
    }

    while( ! feof(in) ){
        a = (int *)malloc(sizeof(int));
        fscanf(in,"%d", &a[size] );;
        printf("a[i]=%d\n",a[size]);
        size++;
    }
fclose(in);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

c arrays malloc file

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

如何将带有"[]"的字符串转换为整数数组

我有两个字符串:

String s1 = "[143, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 157, 158, 159, 162, 163, 164]";

String s2 = "[20, 35, 74, 78, 124, 125, 126, 127, 131, 132, 143, 144, 145, 146]";
Run Code Online (Sandbox Code Playgroud)

我想要做的就是找到这两个字符串中最小的公共数字.所以我首先取代"[]"符号,并将字符串中的数字提取为整数.然后使用循环查找最小公共数.程序如下:

s1 = s1.replace("[",""); 
s1 = s1.replace("]","");
String [] band = s1.split(",");     
s2 = s2.replace("[",""); 
s2 = s2.replace("]","");
String [] hotel = s1.split(",");    
System.out.println( EarliestCommonSlot(hotel,band) );
Run Code Online (Sandbox Code Playgroud)

EarliestCommonSlot()定义如下:

public static int EarliestCommonSlot(String [] a1, String [] b1){
    int i=0,j=0;
    int common = …
Run Code Online (Sandbox Code Playgroud)

java string get

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

标签 统计

c ×3

arrays ×1

file ×1

get ×1

iso-8859-1 ×1

java ×1

malloc ×1

random ×1

string ×1