小编Ske*_*lio的帖子

C编程语言中的指针混淆

大家好,新年快乐!

我很难理解C语言中的指针.据我所知,指针是一个存储常规变量地址的特殊变量.

我正在发布两个相同的代码示例.在第一次我输入scanf中&d1.am.

在第二个示例中,如果我更改&d1.amptd1.am它会弹出编译错误,我无法理解为什么.

struct student{
    int am;
    char stname[20];
    char stsurname[20];
};

int main(){

struct student d1;
printf("1st student\n");
printf("Enter am\n");
scanf("%d", &d1.am)
Run Code Online (Sandbox Code Playgroud)

第二个等效样本:

struct student{
    int am;
    char stname[20];
    char stsurname[20];
};

int main(){

struct student d1;
struct student *ptd1;
ptd1=&d1;
printf("1st student\n");
printf("Enter am\n");
scanf("%d", &(*ptd1).am);
Run Code Online (Sandbox Code Playgroud)

我知道正确的是键入&(*ptd1).am但我无法理解为什么.如何&(*ptd1).am等于&d1.am和不等ptd1.am?我打字清楚了ptd1=&d1!

在此先感谢您的帮助!

c pointers

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

C:定义用户可以声明其大小的全局数组变量

我想用C语言设置一个int数组的全局引用,但我想在main函数中初始化它(实际上用户将声明它的大小).谁知道这是怎么做到的?

提前致谢!

c arrays input

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

用结构体理解 typedef

我很难理解这个代码示例:

typedef struct node
{
        int data;
        struct node * next;
} node;

typedef node * nodepointer;
Run Code Online (Sandbox Code Playgroud)

所以,我们正在使用 typedef 构建结构节点......我假设我们这样做是为了在不需要“struct”关键字的情况下初始化结构。

我想问一下为什么在结构定义中我们使用了两次名称“节点” (在开始和结束时)。

其次typedef node * nodepointer;指向什么。在这种情况下是否有必要使用 typedef?这个表达式node * nodepointer;不相等吗?

c struct typedef

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

Python打印"角色

我该如何打印"角色?

我知道打印%符号print "%%"但我不知道如何打印"字符.

python string

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

如何引用Windows窗体的所有者?

Visual Studio 2013,Visual C#,Windows窗体应用程序.

我对两个Form类感兴趣.该AfterTheGameForm.csTheGameForm.cs.

只有当用户点击第二个按钮时,第一个弹出窗口才会弹出.

AfterTheGameForm afterTheGameForm = new AfterTheGameForm();
afterTheGameForm.Show(this);
Run Code Online (Sandbox Code Playgroud)

所以很明显TheGameForm是AfterTheGameForm的所有者.这就是我的问题...... 在AfterTheGameForm类中, 我想引用Owner类以使用它的特定方法.我肯定知道所有者属于TheGameForm,我正在尝试施放:

TheGameForm gForm = (TheGameForm)this.Owner;
        if(gForm!=null){               
            MessageBox.Show(theGameForm.CheckedRadioButton);
        }
        else
        {
            MessageBox.Show("theGameForm==null");
        }
Run Code Online (Sandbox Code Playgroud)

我也试过这个演员:

TheGameForm gForm = this.Owner as TheGameForm;
Run Code Online (Sandbox Code Playgroud)

gForm对象为null!怎么可能?

c# winforms

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

如何以编程方式在 TableLayoutPanel 上应用列样式和行样式?

一开始有一个只有一行没有列的 TableLayoutPanel。通过按下按钮,我希望该面板变成5 行 3 列

private void button_Click(object sender, EventArgs e)
    {
        this.tableLayoutPanel1.ColumnCount = 3;
        this.tableLayoutPanel1.RowCount = 5;
    }
Run Code Online (Sandbox Code Playgroud)

问题是你得到这个结果!

在此输入图像描述

正如您所看到的,使用行和列创建的框在面板中不包含相同的区域。

在 3 列 5 行的情况下,列必须共享 tablelayoutpanel 的 100%,因此每列 30%。5行的情况下,每行必须占20%。

因此,我将接下来的两行代码附加到button_Click 方法中。

this.tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 20F));
Run Code Online (Sandbox Code Playgroud)

但我得到同样的结果!我缺少什么?

c# tablelayoutpanel winforms

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

StreamWriter:如何添加新行?

我想将字符串写入文件。我的问题是我无法在文件中添加新行。

using (System.IO.StreamWriter writer = new System.IO.StreamWriter(String.Format("{0}.txt", svDialog.FileName)))
            {
                writer.Write(String.Format("{0}\n\n{1}", this.currentRealWorldObj.Title, this.currentRealWorldObj.Description));
            }
Run Code Online (Sandbox Code Playgroud)

如您所见,我在 String.Format 方法中添加了 2 个新行(“\n\n”)。但是当我打开这些行时没有添加。如何添加它们?

c# file-io

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

为什么我不能调用基类构造函数?

我有一个班的孩子System.Drawing.Bitmap.我试图调用它的构造函数,但我在调用基类构造函数时遇到了问题.

更具体地说,我想调用那个特定的构造函数:

Bitmap(String):从指定的文件初始化Bitmap类的新实例.

我认为问题在于它无法识别我的类继承自Bitmap类,因为错误引用了Object类.

无论如何,这是我的班级:

class MyBitmap : Bitmap
{
    private String photographer, description, title;
    public String Photographer
    {
        get
        {
            return this.photographer;
        }
    }
    public String Description
    {
        get
        {
            return this.description;
        }
    }

    public String Title
    {
        get
        {
            return this.title;
        }
    }

    public MyBitmap(String filePath, String title, String description, String photographer) : base(filePath)
    {
        this.title = title;
        this.description = description;
        this.photographer = photographer;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# constructor

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