Thread: Read a file in windows using c code from a linux machine

  1. #1
    Registered User
    Join Date
    Feb 2017
    Posts
    4

    Read a file in windows using c code from a linux machine

    I have a win7 PC with a folder "c:\temp" set-up for sharing. I see State: Shared below the folder. I have a small RISC machine running linux. I wrote a c program on the linus machine to access the win7 folder. The RISC and win7 PC are connected using a cross-over cable.

    In my code, I have the following line:

    fp = fopen("////169.254.5.155//temp//test1.txt", "w+");

    followed by a fprintf statement.

    When I run the c program on the linux machine, I get Segmentation fault. The IP you see is that of the win7 PC.
    Please Help.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    You presumably mean all of those forward slashes to be backslashes. Alternatively, you could just use half as many forward slashes.

    But I still don't think it will work.

  3. #3
    Registered User
    Join Date
    Feb 2017
    Posts
    4
    I just tried
    fp = fopen("\\169.254.5.155\temp\test1.txt", "w+");
    and I have a file on my linux machine named
    \169.254.5.155\temp\test1.txt
    and nothing in c:\temp on the win7 machine

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    I assume you mean those to be forward slashes this time! You either need to use single forward slashes: "//1.2.3.4/one/two/three" or double backslashes "\\\\1.2.3.4\\one\\two\\three". And the first one being doubled ("//" or "\\\\") probably doesn't have any effect (on linux, at least).

    Anyway, I don't know how to do what you want.

    I doubt it's just a matter of sticking the IP address in front of the file name like that ... although it could be, I guess. More likely there's some directory (like /dev or a subdirectory of it) on the linux machine where the IP exists. So it would be something like "/dev/ip/1.2.3.4/temp/test1.txt". But I'm just making that up.

  5. #5
    Registered User
    Join Date
    Feb 2017
    Posts
    4
    I have tried many combinations.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,124
    linux smb mount - Google Search
    You need to create a local mount point of the network shared folder before you can access it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SSH'ing from a windows machine to a linux machine
    By BinaryProgamer in forum Networking/Device Communication
    Replies: 2
    Last Post: 12-11-2014, 10:56 PM
  2. Replies: 4
    Last Post: 01-18-2008, 07:05 PM
  3. Linux OS to Windows OS code
    By sw9830 in forum C Programming
    Replies: 2
    Last Post: 02-28-2003, 03:11 PM
  4. Is it harder to code for Linux or Windows?
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-28-2002, 11:24 PM
  5. Wow! Windows and Linux users please read!
    By Justin W in forum Linux Programming
    Replies: 11
    Last Post: 01-11-2002, 06:06 AM

Tags for this Thread