分配字符时的struct erreur

时间:2019-03-19 20:49:42

标签: c

我遇到此错误:

  

警告:赋值使指针产生整数,而没有强制转换error: object of type 'Case' cannot be assigned because its copy assignment operator is implicitly delete   Private Sub Text1_LostFocus(Index As Integer) Select Case Index Case 1 Grid.Clear fechainicial = "01/" & Text1(1) & "/" & Text1(0) numdias = DaysInMonth(fechainicial) Grid.Cols = numdias + 2 For i = 0 To numdias With Grid .Redraw = False .Rows = 4 .FixedRows = 2 For ii = 0 To .Rows - 1 .RowHeight(ii) = 300 Next .RowHeight(2) = 0 .ColWidth(0) = 300 .ColWidth(i + 1) = 450 If i <= .Cols - 3 Then .TextMatrix(0, i + 1) = Format(CStr(FormatDateTime(fechainicial + i, vbShortDate)), "d") .TextMatrix(1, i + 1) = UCase(Format(i + 1 & "/" & Text1(1) & "/" & Text1(0), "ddd")) End If If Weekday(fechainicial + i, vbMonday) = 7 Then numc = i + 1 fila = 1 .Col = numc .Row = fila .CellForeColor = vbRed .TextMatrix(2, i + 1) = "D" End If .ColWidth(.Cols - 1) = 900 .TextMatrix(0, .Cols - 1) = "HORAS" .Col = 1 .Row = 3 .Redraw = True End With Next i 'End If End Select End Sub

在编译此代码时:

[-Wint-conversion]

3 个答案:

答案 0 :(得分:2)

TabPart[0].nom[20]="alami";

您应该将其替换为

strcpy(TabPart[0].nom, "alami");

TabPart.nom [0]是char,而“阿拉米”是char*(即pointer to a char)。

您不能将char分配给pointer to a char,因为它们不兼容。

答案 1 :(得分:1)

您不能只在带有=符号的结构中分配char。您需要使用strcpy之类的函数将其复制到char数组中。

答案 2 :(得分:1)

您试图将char *分配给char数组的元素,这不是您想要的。您可以使用strcpy将其复制到数组中,或者可以使用字符串文字初始化字符数组。

typedef struct
{
  char nom[20];
  char prenom[30];
  int dej;
  int din;
  int hot;
  int num;
}Participant;

Participant TabPart[10] = {{"alami", "iliass", 0, 1, 2, 1}};

或者,您可以使用指定的初始化程序来更明确地说明每个字段是什么:

Participant TabPart[10] = {{ .nom = "alami", .prenom = "iliass", .dej = 0,
        .din = 1, .hot = 2, .num = 1}};