我正在完成任务,我收到了这个警告:
C4_4_44.c:173:2: warning: format ‘%f’ expects argument of type ‘float *’,
but argument 2 has type ‘double *’ [-Wformat]
Run Code Online (Sandbox Code Playgroud)
变量在main中声明为:
double carpetCost;
Run Code Online (Sandbox Code Playgroud)
我把这个函数称为:
getData(&length, &width, &discount, &carpetCost);
Run Code Online (Sandbox Code Playgroud)
这是功能:
void getData(int *length, int *width, int *discount, double *carpetCost)
{
// get length and width of room, discount % and carpetCost as input
printf("Length of room (feet)? ");
scanf("%d", length);
printf("Width of room (feet)? ");
scanf("%d", width);
printf("Customer discount (percent)? ");
scanf("%d", discount);
printf("Cost per square foot (xxx.xx)? ");
scanf("%f", carpetCost);
return; …Run Code Online (Sandbox Code Playgroud) 我的课堂学期快结束了,我正在做一项作业,根据老师分配的函数原型,编写一个函数来查找字符串中某个字符的编号。我知道我一定在做一些愚蠢的事情,但是这段代码在我的函数中要么锁定要么无限循环。
这是一项任务,所以我不是在寻找任何人为我做作业,而只是指出我错在哪里以及为什么,这样我就可以了解如何解决它。如果您愿意提供任何帮助,我将不胜感激。
这是我写的代码:
#include <stdio.h>
#include <string.h>
int charCounter(char* pString, char c);
int main(void)
{
char* inpString = "Thequickbrownfoxjumpedoverthelazydog.";
int charToCount;
int eCount;
eCount = 0;
charToCount = 'e';
eCount = charCounter(inpString, charToCount);
printf("\nThe letter %c was found %d times.", charToCount, eCount);
return 0;
} // end main
int charCounter(char* pString, char c)
{
int count = 0;
char* pTemp;
do
{
pTemp = strchr(pString, c);
count++;
}
while(pTemp != NULL);
return count;
} // end countCharacter
Run Code Online (Sandbox Code Playgroud) 我是QT的新手,很喜欢编程,而且不了解QT课程的所有帮助材料.
我有以下代码,在按钮单击,插入文本时执行.这工作正常,但我想首先清除textEdit,然后插入新文本.任何人都能指出我在正确的方向吗?任何帮助深表感谢.
QTextCharFormat textFormat;
QTextCursor cursor(ui->textEdit->textCursor());
cursor.insertText("<some text to insert", textFormat);
Run Code Online (Sandbox Code Playgroud)
看来我必须使用setPosition()和movePosition()来选择文本,然后使用removeSelectedText()来清除它.我不知道如何确定文件中的第一个和最后一个位置.
我一直在将数组传递给函数时遇到问题.我将它传递给一个函数并更新它,然后在main中打印值,它们打印得很好.我将它们传递给另一个函数来评估它们,并且这些值由于某种原因不能成功.我已经尝试将它们作为const char和const int传递,或者只是作为char和int传递.他们仍然没有工作.
我落后于我的家庭作业,并以此为结局.你能看出我做错了什么吗?我在Ubuntu上编译GCC.正如我所说,main()中的相同循环产生了正确的结果,并且我正在以一种在设置值的早期函数中正常工作的方式将数组传递给函数.
在主()
evalGuesses(guessType, numberOfGuesses);
Run Code Online (Sandbox Code Playgroud)
在evalGuesses()中
void evalGuesses(char guessType[], int numberOfGuesses)
{
int count;
for(count = 0; count < numberOfGuesses; count++);
{
printf("\n** Eval: option %c", guessType[count]);
}
return;
} // end evalGuesses
Run Code Online (Sandbox Code Playgroud)