我正在用ncurses编写一个小型控制台游戏(作为一项学习任务),我已经遇到了一些小问题(这是我第一次在C中使用列表),但从来没有一个真正的showstopper.但是,作为"未来的供应",我想实现一个基本的调试日志文件.这就是事情开始表现得很奇怪的地方.
日志文件是全局声明的,fopen()(使用w +模式)和ferror()没有显示任何错误证据.相反,一切似乎完美无缺,创建了日志文件,信息被写入其中.但是,在我将一些调试输出添加到各种功能之后,游戏只是段错误.作为一个结果,我几乎将每个调试输出都注释掉了,现在这个简单的代码行崩溃了整个游戏:
fprintf(debuglog, "loop_game()\n\tTime's over! Returning 0\n");
Run Code Online (Sandbox Code Playgroud)
我使用gdb运行程序,并且bt full输出以下内容:
#0 0x00007ffff7886f24 in fwrite () from /lib/libc.so.6
No symbol table info available.
#1 0x000000000040224f in loop_game (pl=0x62d800, list_win=0x62f930,
timer=0x632620, list_ob=0x632640) at game.c:207
elapsed = 60
#2 0x0000000000402d53 in main () at main.c:62
pl = 0x62d800
list_win = 0x62f930
timer = 0x632620
list_ob = 0x632640
Run Code Online (Sandbox Code Playgroud)
(game.c:207是我之前提到的那条线)另外,有人告诉我应该使用watch debuglog,其输出如下:
Old value = (FILE *) 0x0
New value = (FILE *) 0x62f6f0
init () at console.c:128
128 fprintf(debuglog, "init()\n\tInitialised ncurses\n"); …Run Code Online (Sandbox Code Playgroud) 我知道主要的签名是:
int main(int argc, char **argv);
Run Code Online (Sandbox Code Playgroud)
但我真的不知道为什么像这样的主要也会起作用:
main(a){}
Run Code Online (Sandbox Code Playgroud)
这是什么'做'?为什么编译器不显示错误?因为我在使用它之前没有声明'a'.
我正在尝试编写一个绘制Spirograph的Python龟程序,并且我不断收到此错误:
Traceback (most recent call last):
File "C:\Users\matt\Downloads\spirograph.py", line 36, in <module>
main()
File "C:\Users\matt\Downloads\spirograph.py", line 16, in main
spirograph(R,r,p,x,y)
File "C:\Users\matt\Downloads\spirograph.py", line 27, in spirograph
spirograph(p-1, x,y)
TypeError: spirograph() missing 2 required positional arguments: 'x' and 'y'
>>>
Run Code Online (Sandbox Code Playgroud)
这是代码:
from turtle import *
from math import *
def main():
p= int(input("enter p"))
R=100
r=4
t=2*pi
x= (R-r)*cos(t)-(r+p)*cos((R-r)/r*t)
y= (R-r)*sin(t)-(r+p)*sin((R-r)/r*t)
spirograph(R,r,p,x,y)
def spirograph(R,r,p,x,y):
R=100
r=4
t=2*pi
x= (R-r)*cos(t)-(r+p)*cos((R-r)/r*t)
y= (R-r)*sin(t)-(r+p)*sin((R-r)/r*t)
while p<100 and p>10:
goto(x,y)
spirograph(p-1, x,y)
if p<10 or …Run Code Online (Sandbox Code Playgroud) 我有一个跨平台(windows 和 unix+xcb)terminal+graphics_window 应用程序,它大部分工作正常,直到您在输入提示处等待太长时间,在重负载下图像可能会消失。:(
我有一个用于解释器(postscript 解释器)的主循环(REPL),它每次围绕其循环调用一个事件处理函数。事件处理程序执行通常是窗口的消息/事件循环的一次迭代。但是输入是用普通的 C i/o 处理的,因此当阻塞时事件处理程序永远不会被调用fgetc()。
图形窗口仅用于输出。它没有按钮,只需要响应 Raise、Map、Expose 等事件。
如何安排在调用堆栈更深处的输入读取循环期间调用事件处理程序?这需要能够使用 POSIX 和 win32 API 来实现。
选项似乎是
其中任何一个可能比其他的疼痛减轻吗?
如果我可以继续使用 unix,那么这似乎可以解决整个问题:
#include <errno.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
void idleproc () { /* simulates calling the event handler
(ie. one slice of the window loop) */
//printf("idle\n");
putchar('.');
}
int idlefgetc (FILE *stream) {
int ret;
do {
ret = fgetc(stream);
idleproc();
} while(ret …Run Code Online (Sandbox Code Playgroud) 典型的1-D数组可以在声明中静态或自动分配.
enum { n=100 };
int arr1[n];
Run Code Online (Sandbox Code Playgroud)
或者通过指针动态分配和访问.
int *arr1m=malloc(n*sizeof*arr1m);
int *arr1c=calloc(n, sizeof*arr1c);
Run Code Online (Sandbox Code Playgroud)
这两种样式都使用相同的语法访问元素.
int i = n/2;
arr1[i] = arr1c[i] = arr1m[i] = 42;
Run Code Online (Sandbox Code Playgroud)
但是当你添加第二个维度时,需要花费一些力气来实现相同的语法.
int arr2[n][n];
int *arr2c=calloc(n*n,sizeof*arr2c);
arr2[5][5] = arr2c[5*n+5] = 23;
Run Code Online (Sandbox Code Playgroud)
如果您将其构造为Iliffe向量,则只能获得双重括号.
int **arr2l=calloc(n,sizeof*arr2l);
for (int j=0; j<n; j++)
arr2l[j]=calloc(n,sizeof**arr2l);
arr2[6][6] = arr2l[6][6] = 72;
Run Code Online (Sandbox Code Playgroud)
但随着尺寸的增加,这变得越来越麻烦.
另一个困难是在访问元素之前检查动态数组的边界(这样您就不会触及未正确分配的内存).在真正的阵列可以使用sizeof运营商确定的界限,但这些动态数组携带它们的大小与他们.
如何定义具有快速,连续布局的结构,如数组,但具有一致的语法,用于访问具有索引列表的元素,这些索引对于2D阵列和3D阵列的工作方式相同; 并且所有动态,动态大小可以传递给函数并从函数返回?
我有一张student桌子和一张takes桌子.该takes表适用于学生已经或正在学习的课程,并且有专栏:
ID, course_id, sec_id, semester, year, grade
Run Code Online (Sandbox Code Playgroud)
我想使用IDfrom student然后用于其他5列使用:
(CS-001, 1, Fall, 2009, NULL)
Run Code Online (Sandbox Code Playgroud)
我知道如何使用insert into takes select, from, where,而且insert into takes values()我还没有看到任何混合来自另一个表的数据以及我放入的新数据.我们正在做的实验应该是在MySQL查询中使用phpMyAdmin完成的.
我很难解释事情,所以如果这没有意义,我很抱歉.谢谢您的帮助.
这是我想要的那种查询:
insert into takes(ID, course_id, sec_id, semester, year, grade)
values(*IDs from student table*, CS-001, 1, Fall, 2009, NULL);
Run Code Online (Sandbox Code Playgroud) 我有这个文件,并在c中输入结构数组.但是我在将struct成员传递给函数时遇到了问题.错误:甚至没有指针或数组值与第58行中的下标有关.我是c的新手并且坚持这个问题一个星期.
代码:
#include <stdio.h>
#include <math.h>
#define SIZE 100
typedef struct list{
int counter;
int year;
double maxrain;
double rank;
} data;
double avg (struct list s, int count);
int main()
{
data a[SIZE];
struct list s;
double sum = 0;
int totalFile = 1; // according to number of csv file
int z, i;
char fName[16];
FILE*fpt;
double mean;
/* reading multiple file */
for (z=1; z<=totalFile; z++)
{
sprintf(fName," ",z);
fpt = fopen(fName,"r");
if(fpt == NULL){
printf("Error opening …Run Code Online (Sandbox Code Playgroud) 标题说明了一切,我认为不需要代码,因为问题在于找到算法本身.