Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to make a program that counts the number of lines of a file, when I try to pass the absolute path to the fopen function, is simply tells me that is not found, here is my code:

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

using namespace std;

int main(int argc, char *argv[])
{
    int i=0;
    char array[100];

        char caracteres[100];
        FILE *archivo;
        archivo = fopen("C:Documents and Settingsjuegos psps.txt","r");
        if (archivo == NULL){cout<<"Dont Work";}
        while (feof(archivo) == 0)
        {
                fgets(caracteres,100,archivo);
                i++;
                }
                cout << "Number of lines:" << i ;
                return 0;
}

How should I pass the absolute path to my program so you can open the file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
582 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use double slashes:

"C:\Documents and Settings\juegos psps.txt"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...