我想测试并查看"char"类型的变量是否可以与常规字符串(如"cheese")进行比较,以进行比较,例如:
#include <stdio.h>
int main()
{
char favoriteDairyProduct[30];
scanf("%s",favoriteDairyProduct);
if(favoriteDairyProduct == "cheese")
{
printf("You like cheese too!");
}
else
{
printf("I like cheese more.");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
(我实际想做的事情比这要长得多,但这是我坚持的主要部分.)那么如何比较C中的两个字符串呢?
我想制作一个允许curried函数调用的语法.
那是:
a() /// good
a()() /// good
a()()() /// good
a(a) /// good
a(a()()) /// good
/// etc
Run Code Online (Sandbox Code Playgroud)
我的第一个刺是这样的:
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
fncall : expr '(' (expr (',' expr)*)? ')';
expr : ID|fncall;
Run Code Online (Sandbox Code Playgroud)
但由于左递归而失败.
每次我试试这个:
long crypt(int *integer)
{
printf("Enter five digit integer:\n");
scanf("%i",integer);
int digit1=integer/10000;
int digit2=(integer%10000)/1000;
int digit3=(integer%1000)/100;
int digit4=(integer%100)/10;
int digit5=(integer%10)/1;
const char *digit1c[10];
const char *digit2c[10];
const char *digit3c[10];
const char *digit4c[10];
const char *digit5c[10];
Run Code Online (Sandbox Code Playgroud)
(还有更多,但这似乎是问题,我会根据要求添加其余的.)
然后它返回此错误:
math2.h:44:20: error: invalid operands to binary / (have ‘int *’ and ‘int’)
math2.h:45:21: error: invalid operands to binary % (have ‘int *’ and ‘int’)
math2.h:46:21: error: invalid operands to binary % (have ‘int *’ and ‘int’)
math2.h:47:21: error: invalid operands to binary % …Run Code Online (Sandbox Code Playgroud) 你如何在 Ruby 中为文件写入换行符?
我写入文件的代码是:
[完整代码请求]
print("Word:") #Prompt for word to scrambe
word = gets.chomp #Inputs word
wordLength = word.length #Gets word length
randomAmount = wordLength * wordLength #Finds out how many ways to randomize
amountDone = 0 #Loop variable for process of randomizing
while amountDone != randomAmount
puts "---------------------------\n"
x = word.chars.to_a.shuffle #Changes each character to an array and randomizez them
File.open("output.txt","a+") {|f| f.write(x)}
puts "#{amountDone}:\n #{x}"
amountDone += 1
puts "---------------------------\n"
end
puts "Type any key to continue..."
endWord …Run Code Online (Sandbox Code Playgroud) 我正在努力实现这一目标:
编写一个接受三个用户输入的程序:作业分数、期中分数和期末考试分数。
这些输入是 float 类型,值应该在 0 到 100 之间。
该程序应以百分比和字母等级的形式计算最终成绩。
• 最终成绩的计算方式为:作业 20%、期中考试 30%、期末考试 50%。字母等级计算为:A(最终成绩 ? 80%)、B(80 > 最终成绩 ? 70%)、C(70 > 最终成绩 ? 60%)、D(60 > 最终成绩 ? 50%)和 F (50 > 最终成绩)。
显示最终成绩和字母成绩。
使用以下代码:
#include <stdio.h>
int checkMark(int);
float getMark();
float computeFinalGrade(float assign, float midterm, float finalExam, float finalGrade);
int computeLetterGrade(float);
int checkMark(int x)
{
while(x<0 || x>100) //While x is a negative number:
{
printf("Invalid entry.Try again:");
scanf("%d",&x);
}
if(x>0 && x<=100)//If x is a positive number:
x=x; …Run Code Online (Sandbox Code Playgroud) 我已经阅读过这样的其他问题,但似乎都没有...我的代码是:
int flowRateFormula(int pipeDiameter,double velocity)
{
int integer3;
integer3=PI*(1/4)*(pow(pipeDiameter,2))*velocity;
return integer3;
}
Run Code Online (Sandbox Code Playgroud)
错误是:
flowRate.c: In function ‘flowRateFormula’:
flowRate.c:38:13: error: invalid type argument of unary ‘*’ (have ‘int’)
Run Code Online (Sandbox Code Playgroud)
该怎么办?BTW PI是定义的