passing value using flat file ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Amera
    New Member
    • Dec 2009
    • 29

    passing value using flat file ?

    hello,

    i have tried alot of things about this but in the end i did it using flat file.

    but the response is so slow -_-"

    i'm passing a character between C and C# using a text file.

    this operation is continuous .I mean C put char in the text then C# read the

    character erase from the file and so on .....

    the C check if the file is in use by checking if it's empty ...if so it writes the value

    otherwise it return "busy" notification.

    but this operation is so slow.


    this is the code :

    C#

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using System.ComponentModel;
    using System.Data;
    
    namespace TestCommand
    {
        class Program
        {
    
            static void Main(string[] args)
            {
    
                Boolean a = true;
    
                while (a)
                {
                checkFile:
                    try
                    {
                        TextReader tr = new StreamReader("test.txt");
                        String x = tr.ReadLine();
                        tr.Close();
                        TextWriter tw = new StreamWriter("test.txt");
                        tw.WriteLine("");
                        tw.Close();
                        switch (x)
                        {
                            case "L":
                                Console.Write("LEFT");
    
                                break;
    
                            case "R":
                                Console.Write("Right");
    
                                break;
    
                            case "F":
                                Console.Write("Forward");
    
                                break;
    
                            case "B":
                                Console.Write("Backward");
    
                                break;
                        }
                        
                    }
                    catch (IOException)
                    {
                        goto checkFile;
                    }
    
                }
    
                }
            }
       }


    C

    Code:
    #!C:\Ch\bin\ch.exe
    
    
    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream.h>
    
    int main(void)
    {
    
    FILE *test1 ;
    
    char x;
    
    char data;
    
    
    test1=fopen("test.txt","r");
    
    while (!feof(test1)) {
    
    fscanf(test1,"%c",&x);
    
    }
    
    if(x == 0)
    {
    test1=fopen("test.txt","w");
    
    data='Y';
    
    fprintf(test1,"%c",data);
    
    fclose(test1);
    
    printf("The entered value is  %c",data);
    
    }
    else 
    
    {
    printf("Controlling is busy");
    
    fclose(test1);
    }
    
    return 0;
    }
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    hello,

    i have tried alot of things about this but in the end i did it using flat file.
    but the response is so slow -_-"
    i'm passing a character between C and C# using a text file.
    this operation is continuous .I mean C put char in the text then C# read the
    character erase from the file and so on .....
    the C check if the file is in use by checking if it's empty ...if so it writes the value otherwise it return "busy" notification.
    but this operation is so slow.
    Ok. You know what you have.

    What you don't have is a question. Nobody here knows why you posted this since you haven't asked anything. What is it you are looking for?

    I recommend you read the FAQ about How to ask a good question so the volunteers will be able to help you.

    In your previous posts on this topic:


    You have been given lots of alternative ideas. What is you are asking now?

    but the response is so slow -_-"
    Well of course it is: You have limited your two applications to the speed of a harddrive; which is like 1,000 times slower than memory.

    Comment

    • Amera
      New Member
      • Dec 2009
      • 29

      #3
      the previous posts , nothing has worked .So i turned to this idea (flat file)

      but the passing operation is very slow.

      Comment

      • Amera
        New Member
        • Dec 2009
        • 29

        #4
        or i should say "the C# reading is so fast that the C always find the file busy"

        Comment

        • Amera
          New Member
          • Dec 2009
          • 29

          #5
          not always but rarely find it available .

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Why not make one program a server and one a client and have them talk over UDP or TCP/IP?

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              i should say "the C# reading is so fast that the C always find the file busy"
              Right... because you have a loop that continuously opens and reads the file.

              Why open the file continuosly if it hasn't changed? Heck, why do it in a loop at all? That's just going to hang your application.

              Read up on the FileSystemWatch er. You can have one throw an event when the LastWrite datetime changes (from your C app). Then read the file only after it has changed.

              Comment

              • Amera
                New Member
                • Dec 2009
                • 29

                #8
                Read up on the FileSystemWatch er. You can have one throw an event when the LastWrite datetime changes (from your C app). Then read the file only after it has changed.
                could you please tell me how can i do that ?

                Comment

                • tlhintoq
                  Recognized Expert Specialist
                  • Mar 2008
                  • 3532

                  #9
                  Happy to. Go to the MSDN and read about the FileSystemWatch er control (its in your Toolbox)

                  Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.

                  Comment

                  Working...