0

正如标题中所说,这个程序的范围是做标量积 beetwen 2 数组,但是它们用逗号分隔值填充,并且它们被写成一个字符串,所以我使用 strtok 来“消除”所有的逗号,然后使用 strtod() 将所有值转换为双精度值,然后将它们与另一个数组中的值相乘,然后求和,以得到标量积。问题是我无法将所有值转换为双精度值,因为它只会停止第一个值。我附上了我所做的所有代码的链接如果您不理解函数的名称,请告诉我。先感谢您

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"insert.h"
#include"p_spazi.c"
#define LEN 100



void insert(char[]);
void pulisci(char[]);
 
 

int main() {
    char s[LEN] = "";
    char l[LEN] = "";
    int i = 0;
    int a;
    double n = 0.0;
    char *s1 = NULL;
    char *s2 = NULL;


insert(s);

//insert(l);
pulisci(s);

s1 = strtok(s, ",");

// this works
while (s1 != NULL){
    printf("S1 contiene %s\n", s1);
    s1 = strtok(NULL, ",");     
}   
// here should go the strtod loop(?)

return 0;
4

0 回答 0