小编Fre*_*son的帖子

为什么此代码会因非行星命令行参数而失败?

我正在编写一个 C 程序的教科书示例,它将接受命令参数并确定它们是否是行星。这是我创建的代码:

#include <stdio.h>
#include <string.h>
#define NUM_PLANETS 9

void main(int argc, char *argv[]){
    char *planets[] = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn"
                        "Uranus", "Neptune", "Pluto"};
    printf("Num args: %d\n", argc);
    
    int i, j;
    
    for(i = 1; i < argc; i++){
        //for every argument on the command line
        printf("arg: %d\n", i);
        for(j = 0; j < NUM_PLANETS; j++){
            //for every planet
            printf("j = %d\n", j); 
            if(strcmp(argv[i], planets[j]) == 0){
                //argument is a planet
                printf("%s is planet %d\n", argv[i], j + …
Run Code Online (Sandbox Code Playgroud)

c

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

C中的链接列表

当我编译这个程序时,我在第45行(注释)中得到一个错误,说明了strcpy的不兼容隐式声明...我复制了部分代码,希望你们能帮助我解决这个问题

#include <stdio.h>

#include <stdlib.h>

#define strsize 30

typedef struct member
{int number;
char fname[strsize];
struct member *next;
}
RECORD;

RECORD* insert (RECORD *it);
RECORD* print(RECORD *it, int j);

int main (void)
{
int i, result;
RECORD *head, *p;
head=NULL;
printf("Enter the number of characters: ");
scanf("%d", &result);

for (i=1; i<=result; i++)
head=insert (head);
print (head, result);

return 0;

}

RECORD* insert (RECORD *it)

{

RECORD *cur, *q;
int num;
char junk;
char first[strsize];
printf("Enter a character:");
scanf("%c", &first);

cur=(RECORD …
Run Code Online (Sandbox Code Playgroud)

c

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

sys.stdout显示我没写的东西

我在做(Python 3.5):

sys.stdout.write('NoNewRecords')
Run Code Online (Sandbox Code Playgroud)

它告诉我:

NoNewRecords12
Run Code Online (Sandbox Code Playgroud)

这是为什么?

我用它来推动价值Apache-Airflow.当我推动时,我需要具有确切的值.

>>> import sys
>>> sys.stdout.write('NoNewRecords')
NoNewRecords12
Run Code Online (Sandbox Code Playgroud)

python

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

导入数学输出错误答案

Import Math 的三角函数不会输出正确的结果。

print(math.tan(math.degrees(60)))
Run Code Online (Sandbox Code Playgroud)

输出 1.1255751154673213。

在我的计算器(deg)上,它输出 1.73205080757

有人知道发生了什么事吗?

python

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

我在以下程序中收到错误,我不确定要做什么

代码如下:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline void keep_window_open() { char ch; cin >> ch; }
int main()
{
  string operation;
  double num1, num2, val;
  cout << "Enter the operation followed by the numbers\n";
  cin >> operation >> num1 >> num2 >> endl;
  if (operation == "+") {
    cout << operation << num1 << num2 << endl;
    val = num1 + num2;
    cout << val << endl;
  }
  if (operation == "-") …
Run Code Online (Sandbox Code Playgroud)

c++

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

在不同的数据类型上使用std :: transform

我有一个名为atom的自定义数据类型.我想用std :: transform来填充双向量,原子成员"number"是一个双倍的女巫.我得到错误"std :: vector :: iterator'没有名为'vec2'的成员",其中vec2是我的双向量.为什么是这样?甚至可以在变换中使用两种不同的数据类型吗?

atom.h

#ifndef _atom_
#define _atom_
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

class atom{

public:

    bool operator==(const atom rhs);
    double number;
    string name;

};
#endif
Run Code Online (Sandbox Code Playgroud)

atom.cpp

#include "atom.h"

atom::atom(){}

atom::~atom(){}

bool atom::operator==(const atom rhs){
    return this->name==rhs.name;

    } 
Run Code Online (Sandbox Code Playgroud)

transformation.h

#ifndef _transformation_
#define _transformation_
#include "atom.h"
#include <vector>
#include <algorithm>
using namespace std;


struct transformation{


    double operator() (atom a) const{

            return a.number;
        }



};
#endif  
Run Code Online (Sandbox Code Playgroud)

main.cpp中

int main(){

    vector<atom> vec;


    atom …
Run Code Online (Sandbox Code Playgroud)

c++ transform std custom-data-type

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

标签 统计

c ×2

c++ ×2

python ×2

custom-data-type ×1

std ×1

transform ×1