丢弃标题行

时间:2019-04-14 02:29:09

标签: c

我有一个.tsv文件,可以在编译读取该文件的代码后直接将其输入到我的代码中,或者使用“ <”直接输入任何内容。 而不是任何fopen,我在整个代码中都使用scanf来读取数据行。 标头是3个非双精度字符,应将其读取然后扔掉,这样我就可以将3列下的每个双精度数放入单独的数组中。

我似乎无法让我的代码跳过.tsv文件的第一行输入,然后继续实际获取3个双精度数并将它们放入3个单独的数组中。

int main(int argc, char *argv[])
{

    int i = 0;
    double X[MAX], Y[MAX], KG[MAX];
    void data_lines();
    while (scanf("%lf%lf%lf",&X[i],&Y[i],&KG[i] )== 3) {
        printf("%lf%lf%lf\n", X[i],Y[i],KG[i]);
        i++;
    }
    printf("%d", MAX);
    return 0;
}

void 
data_lines() {
    char ch;
    while (scanf("%c",&ch)!=EOF) {
        if (ch == '\n'){
            return;
        }
    }
}

当我输出此代码时,我得到的全部是999打印的。 因此,我猜测阵列中没有任何内容,并且第一条数据行也没有被跳过。

1 个答案:

答案 0 :(得分:0)

以下建议的代码:

  1. 干净地编译
  2. 执行所需的功能

请注意前向参考/原型

请注意子函数的调用方式

请注意包含头文件Sub Private_Button_Push() 'On Error GoTo ErrorHandler Dim myMail As MailItem Set myMail = Application.ActiveInspector.CurrentItem If myMail.Class <> olMail Then Exit Sub Dim strPrivacyStatement As String strPrivacyStatement = "ABC Ltd - Strictly Private & Confidential" Select Case myMail.Sensitivity Case olPrivate 'If MsgBox("Remove 'private' setting?", vbYesNo, "Sensitivity: 'normal'") = vbNo Then Exit Sub myMail.Sensitivity = olNormal Privacy_Wording False, strPrivacyStatement 'MsgBox "This email has been made non-private again.", vbOKOnly, "Sensitivity: Normal" Case Else myMail.Sensitivity = olPrivate Privacy_Wording True, strPrivacyStatement End Select Exit Sub ErrorHandler: Select Case Err.Description Case Is = "The sensitivity of this message cannot be changed. The message contains information that has been marked as private by the original author." MsgBox Err.Description, vbOKOnly, "Private email." Case Else MsgBox "Please report the following error number to the IT Department: " & Err.Number, vbCritical, "Privacy setting error." End Select End Sub Sub Privacy_Wording(SetPrivate As Boolean, strText As String) Dim myInspector As Outlook.Inspector Dim myItem As MailItem Dim myFirstLine As String Dim myDoc As Word.Document Dim mySel As Word.Selection Set myInspector = Application.ActiveInspector Set myItem = myInspector.CurrentItem Set myDoc = myInspector.WordEditor Set mySel = myDoc.Windows(1).Selection myFirstLine = myDoc.Range.Paragraphs(1).Range Select Case SetPrivate Case True cPar = myDoc.Range(0, mySel.Paragraphs(1).Range.End).Paragraphs.Count With myDoc.Range .Collapse .InsertBefore vbCr & vbCr .Font.Name = "Arial" .Font.Size = 10 .Font.ColorIndex = wdBlack .Font.Bold = False .Collapse .InsertBefore strText & vbCr .Font.Bold = True .Font.Name = "Arial" .Font.Size = 8 End With If cPar = 1 And myFirstLine = Chr(13) Then mySel.Move wdParagraph, 2 Case False For I = 3 To 1 Step -1 With myDoc.Range.Find .Text = strText For x = 1 To I .Text = .Text & vbCr Next x .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True .Execute Replace:=wdReplaceAll If .Found = True Then Exit Sub End With Next I End Select End Sub 的方式

请注意MAX的定义

现在,建议的代码:

stdio.h