我有一个明显容易的问题,但我无法得到我做错了什么.我有一个代码可以在控制台中测试60个字符的输入文本,如果在该文本中出现"恐怖"字样,它将提示消息"可疑文本",当该字出现时,它将显示"没有任何可疑" .进入"模式"的文本应在输入单词"完成"时结束.这似乎是我的问题,因为我的while循环只是不想结束.
任何提示?
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
int start_with (char *sir1, char *sir2)
{
int i,j,k;
int len_sir2=strlen(sir2);
char sir3[60]="";
for (i=0;i<=len_sir2;i++)
{
sir3[i]=sir1[i];
}
k=(strcmp(sir2,sir3)) ? 0:1;
return k;
}
int main()
{
char *txt1;
char sir1[60]="", sir2[60]="terorist", sir_test[60]="done";
int i,j,lensir1, contor=0,buf_de_la=0, buf_la;
while (sir1!=sir_test)
{
printf("Enter desired text and press ENTER \n");
gets(sir1);
printf("\n");
buf_la=strlen(sir1);
char *txt1="Nothing suspect";
while (buf_de_la<buf_la-7)
{
char sirbuf[60]="";
j=buf_de_la;
for (i=0;i<=7;i++)
{
sirbuf[i]=sir1[j];
j=j+1;
}
if (start_with(sirbuf,sir2)==1)
{
txt1="SUSPECT …Run Code Online (Sandbox Code Playgroud) void verification() {
char pass[50];
printf(" Enter Password : ");
fgets(pass, 50, stdin);
if (pass != 'aaanc6400') { \\ Warning message in here
printf("\n Invalid Password.. Please enter the correct password. \n\n");
verification();
}
info();
}
Run Code Online (Sandbox Code Playgroud)
当我编译程序时,在标记的行上它显示警告"字符常量对于它的类型太长"以及"指针和整数之间的比较".然后当我运行代码并输入正确的密码时,它仍会输出密码错误.我究竟做错了什么?
我有这样的文本文件
"input"
height : 227
width : 227
depth : 3
"conv"
num_output : 96
pad : 0
kernel_size : 11
stride : 4
group : 1
"relu"
"pool"
kernel_size : 3
stride : 2
Run Code Online (Sandbox Code Playgroud)
我在循环中读它(这是部分代码)
char line[100];
while ((fgets(line, sizeof(line), filePtr))) {
if (line[0] != "\n") {
sscanf(line, "%15s : %15s", tmpstr1, tmpstr2);
printf("%s\n", tmpstr2);
printf("line = %s", line);
} else
break;
}
Run Code Online (Sandbox Code Playgroud)
但我观察到if条件总是成立,输出如下
"input"
227
line = height : 227
227
line = width : 227 …Run Code Online (Sandbox Code Playgroud) 我是C初学者,我不明白为什么这段代码不起作用?
void main(){
char userInput = "a";
if(userInput == "a"){
printf("a");
} else printf("b");
getch();
}
Run Code Online (Sandbox Code Playgroud)
返回"b"
但这一个正在发挥作用
void main(){
char userInput;
if("a" == "a"){
printf("a");
} else printf("b");
getch();
}
Run Code Online (Sandbox Code Playgroud)
返回"a"
有什么不同?
我的老师指派我strcmp()在C中编写自己的函数.我确实创建了自己的函数版本,我希望得到一些反馈.
int CompareTwoStrings ( char *StringOne, char *StringTwo ) {
// Evaluates if both strings have the same length.
if ( strlen ( StringOne ) != strlen ( StringTwo ) ) {
// Given that the strings have an unequal length, it compares between both
// lengths.
if ( strlen ( StringOne ) < strlen ( StringTwo ) ) {
return ( StringOneIsLesser );
}
if ( strlen ( StringOne ) > strlen ( StringTwo ) ) { …Run Code Online (Sandbox Code Playgroud) 我试图让这个程序说得好但是它说好了但是我把变量值与if测试值相同
#include <stdio.h>
#include <stdlib.h>
int main()
{
char history[200];
history == "NY school";
if(history == "NY school")
{
printf("good");
}
else{printf("okay");}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 代码是:
#include<stdio.h>
int main()
{
char *st1="hello";
char *st2="hello";
if(st1==st2)
printf("equal %u %u",st1,st2);
else
printf("unequal");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到输出"相等4206628 4206628".
我觉得我错过了一些非常明显的东西......
在我的程序中,我使用编辑框读取用户输入GetWindowText(),
然后是以下代码:
if (x == L"R" || x == L"C" || x == L"L"){ n = 1; }
else{ n = 9; }
Run Code Online (Sandbox Code Playgroud)
调试器清楚地说x是L"R",但是n设置为9.
是使用if()在这种情况下错了,我应该用别的东西吗?
我必须编写一个功能类似于 dos2unix 的 C 程序。将全部替换CR LF为LF(DOS-Format to Unix-Format)。所以这是我的方法。每次我读一行时,我都会通过lookng for 来搜索数据的结尾\0,然后检查以下是否是\r\n. 如果是,\n只替换。但它似乎不起作用,并且该行CRLF here从未打印过一次。
char data[255]; // save the data from in.txt
char *checker;
pf = fopen("in.txt", "r");
pf2 = fopen("out.txt", "w");
while (feof(pf) == 0)
{
fgets(data, 255, pf); // Read input data
checker = data;
while (checker != "\0") // Search for a new line
{
if (checker == "\r\n") // Check if this is CR LF
{ …Run Code Online (Sandbox Code Playgroud) 这是我的情况的简化:
头文件.h
#DEFINE NUMBER 3
extern char reserved[][];
Run Code Online (Sandbox Code Playgroud)
定义器
char reserved[NUMBER][4] = {"WOW","LOL","K"}
Run Code Online (Sandbox Code Playgroud)
符号.c
#include "header.h"
void theFunctionWithTheError{
if (reserved[1] == "I love stackoverflow"){ /**THE LINE OF THE ERROR*/
return;
}
}
Run Code Online (Sandbox Code Playgroud)
在 sign.c 中,我收到错误Expression must be a pointer to a complete object type
for the wordreserved
你建议我做什么?