delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/23/23:26:25

From: tonyblaha AT juno DOT com
To: djgpp AT delorie DOT com
Subject: reading/writing to COM ports
Message-ID: <19980823.222639.6511.0.tonyblaha@juno.com>
Date: Sun, 23 Aug 1998 23:22:55 EDT

I'm a very new C programmer, and I was wanting to write a small
speed-dial program with djgpp for msdos. How can I read/write from a COM
port? Looking at the documentation I thought maybe I could use "inp" and
"outp" from PC.H, but I don't know how to use them.

Basically what I want to do is to pass a string like "atz" or "atdt
5551234" to COM 2, and then read in any replies. Could someone email me
some *simple* code of how I would do this, heavily annotated with
comments on what the different functions are and how to use them? Or
basically any help would be appreciated.


Second (and less important) why in the following code does it output the
strings reversed? What I mean is, I write three strings to the file, and
then read three strings from the file. Why does it matter what variables
I use to read the strings? Shouldn't it just read in the first, second
and third strings in strC, strB & strA, in that order?
(Also: Could I shorten this program in any way? Am I doing anything that
I don't need to, or doing anything a long way?)

- - - - - Cut Here - - - - - 

#include <STDIO.H>

int main() 
{

char strA[255], strB[255], strC[255];
FILE *fp;

if(!(fp=fopen("TEST", "w"))) {
	printf("Cannot open test file.");
	exit(1);
}

printf("Enter 1st string: ");
fscanf(stdin, "%s", strA);

printf("Enter 2nd string: ");
fscanf(stdin, "%s", strB);

printf("Enter 3rd string: ");
fscanf(stdin, "%s", strC);

fprintf(fp, "%s %s %s", strA, strB, strC);

fclose(fp);

if(!(fp=fopen("TEST", "w"))) {
	printf("Cannot open test file.");
	exit(1);
}

fscanf(fp, "%s %s %s", strC, strB, strA);

printf("\n%s\n%s\n%s", strC, strB, strA);

fclose(fp);

return(0);
}

- - - - - Cut Here - - - - -



TIA,
Tony Blaha

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019