小编Thi*_* G.的帖子

在引号内使用引号

当我想print在Python中执行命令并且我需要使用引号时,我不知道如何在不关闭字符串的情况下执行此操作.

例如:

print " "a word that needs quotation marks" "
Run Code Online (Sandbox Code Playgroud)

但是当我尝试做我上面做的事情时,我最终关闭了字符串,我不能把我需要的字放在引号之间.

我怎样才能做到这一点?

python string

54
推荐指数
4
解决办法
22万
查看次数

编译在Mac OS X中使用OpenGl的C程序

我正在尝试为我的CS类编译一个C程序.我的Mac上安装了命令行工具,所以我可能有OpenGL.程序描述是为Ubuntu制作的,它说我可以使用以下方法编译:

gcc -Wall -ansi -pedantic -O2 main.o graphic.o imagem.o io.o -o ep2 -lGL -lGLU -lglut
Run Code Online (Sandbox Code Playgroud)

我跑了,它说:

ld: library not found for -lGL
Run Code Online (Sandbox Code Playgroud)

我应该使用什么标志?我该怎么办?

c opengl macos gcc

9
推荐指数
2
解决办法
1万
查看次数

我需要释放局部变量吗?

我有以下内容struct:

typedef struct cell Cell;
struct cell {
    int value;
    int *nextcell;
};
Run Code Online (Sandbox Code Playgroud)

我有以下功能来释放链表:

void freelist(Cell *beginning)
{
    Cell *thisCell = beginning;
    Cell *NextCell = beginning->nextcell;

   while (thisCell != NULL)
   {
        NextCell = thisCell->nextcell;
        free(thisCell);
        thisCell = NextCell;
   }

   /* Here comes my question. Do I need to free the following variables? */
   free(beginnig);
   free(thisCell);
   free(NextCell);
}
Run Code Online (Sandbox Code Playgroud)

c free pointers linked-list

9
推荐指数
1
解决办法
4390
查看次数

将动态分配的数组作为参数传递给C语言

所以...我在我的主要上有一个动态分配的数组:

int main()
{
    int *array;
    int len;

    array = (int *) malloc(len * sizeof(int));
    ...
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

我还想构建一个函数,用这个动态分配的数组做一些事情.到目前为止我的功能是:

void myFunction(int array[], ...)
{
   array[position] = value;
}
Run Code Online (Sandbox Code Playgroud)

如果我将其声明为:

void myFunction(int *array, ...);
Run Code Online (Sandbox Code Playgroud)

我还能做到:

array[position] = value;
Run Code Online (Sandbox Code Playgroud)

或者我将不得不这样做:

*array[position] = value;
Run Code Online (Sandbox Code Playgroud)

...?

此外,如果我正在使用动态分配的矩阵,哪一个是声明函数原型的正确方法:

void myFunction(int matrix[][], ...);
Run Code Online (Sandbox Code Playgroud)

要么

void myFunction(int **matrix, ...);
Run Code Online (Sandbox Code Playgroud)

...?

c arrays matrix

4
推荐指数
1
解决办法
1万
查看次数

Python - 从整数中提取字符

我正在尝试在python中创建一个算法,要求您插入一个数字,然后从插入的数字打印数百,数十和单位.

我想要做的是从与数百个对应的数字中提取字符并将其打印为数百个,以及数十个单位.

例如,我到目前为止尝试做的是:

number = 321 
print 'Hundreds: ', number[1]
Run Code Online (Sandbox Code Playgroud)

但是,当我试图运行它时,我收到了消息:

TypeError: 'int' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)

做我想做的事是不可能的吗?

python

1
推荐指数
1
解决办法
6848
查看次数

Python - 删除字符串中的空格

所以,我想在语句的末尾打印一个带有感叹号的字符串,但在最后一个单词和感叹号之间没有任何空格.例如:

name = raw_input('Insert your name: ')
Run Code Online (Sandbox Code Playgroud)

现在,我希望python打印这样的东西:

你的名字是约翰!

所以,我输入:

print 'Your name is', name, '!'
Run Code Online (Sandbox Code Playgroud)

它让我回报:

你的名字是约翰!

我想要做的是删除"约翰"和感叹号之间的空格.

有任何想法吗?

python

1
推荐指数
1
解决办法
945
查看次数

Python - 打印一定数量的字符串

可能重复:
Python,多次打印,

我想知道如何打印诸如"String"之类的字符串500次?

python

0
推荐指数
1
解决办法
3万
查看次数

标签 统计

python ×4

c ×3

arrays ×1

free ×1

gcc ×1

linked-list ×1

macos ×1

matrix ×1

opengl ×1

pointers ×1

string ×1