我必须比较2个字符串,一个来自文件,一个来自用户输入,这里是文件:
Password
abcdefg
Star_wars
jedi
Weapon
Planet
long
nail
car
fast
cover
machine
My_little
Alone
Love
Ghast
Run Code Online (Sandbox Code Playgroud)
从行中获取字符串的代码很好但是用于比较2个字符串的代码没有给出正确的输出
int main(void){
int loop, line;
char str[512];
char string[512];
FILE *fd = fopen("Student Passwords.txt", "r");
if (fd == NULL) {
printf("Failed to open file\n");
return -1;
}
printf("Enter the string: ");
scanf("%s",string);
printf("Enter the line number to read : ");
scanf("%d", &line);
for(loop = 0;loop<line;++loop){
fgets(str, sizeof(str), fd);
}
printf("\nLine %d: %s\n", line, str);
if(strcmp(string,str) == 0 ){
printf("Match"); …Run Code Online (Sandbox Code Playgroud) 我刚开始学习java,因为我想制作Android应用程序.到目前为止我只知道c.我正在读一本名为"Head first java"的书,它一直在谈论对我来说很新鲜的对象和类.我只有一个问题,如果有人可以为我澄清这一点,那将是非常有用的:类(java)和结构(c)之间的区别是什么?ps:如果你能推荐给我一本真正适合绝对初学者的书,我也很喜欢,因为我现在正在阅读的书中没有足够的细节来介绍那些对面向对象编程完全不熟悉的书.谢谢.
struct Book {
int i;
} variable, *ptr;
Run Code Online (Sandbox Code Playgroud)
在访问结构成员时,我们使用 variable.i 或 ptr->i 我的问题是变量和 *ptr 的使用/使用之间有什么区别
我有一个私人结构的课程.如何访问该结构的数据成员?
class ClassStruct
{
private:
struct Struct
{
std::string time;
int temp;
};
public:
ClassStruct();
};
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
struct Struct o;
ClassStruct object;
cout << "Enter time (hh:mm): ";
cin >> object.o.time;
Run Code Online (Sandbox Code Playgroud)
但它在"o"上显示错误.
你好,我对如何在不使用指针的情况下通过带有结构的函数正确传递数组感到困惑.我们只应该使用第1-8章,其中不包括指针..这里是我的代码,如果有人有任何建议或链接,以帮助谢谢!
const int MAX_DATA = 10000;
struct Inventory
{
double sku;
double count;
double cost;
string title;
};
void addMovie(Inventory data[], double count);
void allInfo(Inventory data[], double count);
int main ()
{
Inventory data[MAX_DATA];
int choice;
int i = 0;
double count = 0;
return 0;
}
void addMovie(Inventory data[], double count)
{
int i = 0;
cout << "Please enter the name of the movie you wish to add " << endl;
cin >> data[i].title;
cin.ignore();
cout << "Please …Run Code Online (Sandbox Code Playgroud) 我理解基本如何struct在C++中工作,如下例所示:
struct Options
{
int num_particles;
bool use_lbp;
string infile;
string outfile;
};
Run Code Online (Sandbox Code Playgroud)
但是,我不明白以下内容,在声明中还有一个附加部分.目的是Options():...什么?
struct Options
{
Options()
:num_particles(NUM_PARTICLES),
use_lbp(false),
infile(),
outfile()
{}
int num_particles;
bool use_lbp;
string infile;
string outfile;
};
Run Code Online (Sandbox Code Playgroud)
这与下面的代码中的内容类似吗?
struct State_
{
State_( State pp ) : p( pp ) { }
operator State() { return p; }
State p;
};
Run Code Online (Sandbox Code Playgroud)