文件不会使用fopen打开

时间:2015-05-30 19:51:32

标签: c csv fopen

我似乎无法打开此.txt文件,它也无法使用.csv文件 我如何让它打开? (这是我试图在csv文件中搜索短语的程序)

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_WIDTH 320

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

    int i = 0, j = 0;
    char bigString[200];
    FILE* csv;
    csv = fopen("C:\Users\Ofek\Desktop\Folder\source.txt","r+t");
    while (feof(csv) != 1)
    {
        if (fgetc(csv) != '\n')
        {
            char bigString[i] = fgetc(csv);
            i++;
        }
    }
}

2 个答案:

答案 0 :(得分:1)

用两个反斜杠替换所有单个反斜杠:

public static void main(String[] args) throws Exception {
    List<Object> list1 = new ArrayList<>(Arrays.asList(1234, 123.45, "999", 444.444, 999.999));
    List<Object> list2 = new ArrayList<>(Arrays.asList("1234", 123.45, "9991", 444.444));

    for (int i = 0; i < list1.size(); i++) {
        // Only check against parallel list if the index is in the bounds
        if (i < list2.size()) {
            // Check if the data types match
            if (!list1.get(i).getClass().getName().equals(list2.get(i).getClass().getName())) {
                System.out.println(String.format("%s: %s != %s: %s", 
                        list1.get(i).getClass().getName(), list1.get(i), 
                        list2.get(i).getClass().getName(), list2.get(i)));
            }
            // Check if the values match if the datatypes match
            else if (!list1.get(i).equals(list2.get(i))) {
                System.out.println(String.format("%s != %s", list1.get(i), list2.get(i)));
            }
        }
    }
} 

否则反斜杠后面的字符将被解释为控制字符。

答案 1 :(得分:1)

发布的代码存在一些问题。以下是一些:

var cur = 1;
var max = $("#featured-slide").children("li").length;

$('button.next-button').click( function() {

if (cur+1 > max) return;
    cur++;

$("#featured-slide").animate({
        right: "+=200px"});
} );

$('button.back-button').click( function() {

if (cur-1 < 1 ) return;
    cur--;

$("#featured-slide").animate({
        right: "-=200px"});
});

以下代码更正了大多数&#39;发布的代码中的问题。

1) do not use 'feof()' for a loop control, it will not work as expected. 
2) when setting the bigString[i] variable, a second call to fgetc() is used. That results in the first, 3, 5, 7, etc characters being lost.
Suggest: save the results of the call to fgetc() in the 'if' statement and use that saved value.