C :: Read From A File Containing Serial Of Number
Jun 2, 2014
I want to read a file who contain a serial of number like in this example : +200,-100,+400,+200,-200 and the sign is very important for the rest of the program so i should save those signed numbers in an array or a struct that i can define with a boolen variable if it's + i give it 1 else if it's - it'll be 0
I wrote a basic file's code reader but i don't think there is a solution on it
Code:
void read_file(char *fil1){
FILE *f;
int ch[500];
f=fopen(fil1,"rt");
if(f==NULL)
[Code] .....
View 1 Replies
ADVERTISEMENT
Dec 29, 2013
Explain me a working code to read and write a file using serial communication.and i need to store that file.I know normal file handling in C, but how it is through serial port i am not getting.
View 1 Replies
View Related
Oct 18, 2014
I read correctly in MatLab some data by serial port of a device, but in C... nothing.
Code: #include <cstdlib>
#include <stdio.h>
int main(void)
{
FILE *in;
char linha[30];
while(1)
{
// Abrir porta COM de onde se ligou a placa
in = fopen( "COM8", "r" );
if( in == NULL )
{
[code].....
The message "ERRO: no consigo abrir porta COM " don't appear, so I haven't error there. I just do not see anything in the terminal.
View 3 Replies
View Related
Apr 14, 2014
I am using libserial library to communicate through the serial port in c++. the linux cpu is communicating with a modem through the serial port. basically this is what i want to do
Code:
//I want:
cpu to write command_1 to modem
Wait for the answer from modem
read serial port
check if command successful (i.e modem sends OK if successful and ERROR if there is an error)
If there is an error, resend command_1
if successful then Write command_2 to modem Wait for answer read again serial port check if command is succesful (modem again sends OK if successful and ERROR if there is an error) basically, this is the code...
Code:
serial_port <<command_1 <<'
'; //send 1st command
sleep(2); //delay a while
[Code].....
View 6 Replies
View Related
Jun 2, 2010
How can i read barcode scanner value from serial port?
View 5 Replies
View Related
Feb 17, 2013
I want to read and write value on serail port to Microcontroller with MFC. The MFC have no serial port tool like in VB Professionnal edition. I try to find MFC connect serial port example but I not found. If you have good example for read and write on serial port with MFC
View 2 Replies
View Related
Jun 27, 2014
I am using libserial library to interact with a modem using c++. The C++ code sends an AT command:
Code:
my_serial_stream << "AT+CSQ" << '
' ;
The modem responds with a response, either ERROR or OK, The c++ code to read the response:
Code:
while( serial_port.rdbuf()->in_avail() > 0 )
{
char next_byte;
serial_port.get(next_byte);
std::cerr << std::hex << (int)next_byte << " ";
}
std::cerr << std::endl;
I would like to handle the response such that if the response is OK, the modem sends another command and if the response is ERROR, the modem resends the first command.
View 1 Replies
View Related
Dec 13, 2013
I want to send data from a laptop (windows 7, processor 2.60GHz) to a desktop (windows xp, processor 3.10GHz) using serial communication (using a USB to RS232 convertor). The WriteFile function is able to send the data from the laptop (NumberOfBytesWritten is correct). But on the desktop side, ClearCommError detects no data in the read buffer.
This is the relevant code in my desktop:
while(1) {
ClearCommError(hPort,&dwErrors,&commStatus);
if (commStatus.cbInQue != 0) ReadFile(hPort,&data,1,&dwBytesRead,NULL);
Sleep(10);
}
The if condition is never satisfied. The baudrate and other parameters in the DCB struct are the same on both sides.
The same code works when I write and read in the same system by shorting the RX and TX pins in the RS232 connector.
View 2 Replies
View Related
Sep 15, 2012
I am trying to retrieve the parameters from externally connected pendrive. I have been using WMI to achieve this but not able to separate the pendrive's parameters from the other USB devices (such as USBcamera,USBHub etc) ....
View 2 Replies
View Related
Sep 15, 2013
I have a file called example.txt . In that file, the int 123456 is stored. How can I read one independent number from that int? Lets say, I have an int variable called "Weight." How do I set weight equal to the number 1 from the int 123456 in the file?
View 4 Replies
View Related
Nov 28, 2014
I am trying to read the name, phone number and address from a file ... Here is the code but it doesn't work and i don't know where is the problem ...
#include <stdio.h>
#include <stdlib.h>
struct PhoneBook{
char name[50];
int phoneNumber;
char address[50];
[Code] ....
And here is the contents of the file:
jack 01014 jgd
Moh 02925 Tyeu
When I run it on dev c++, a message appear saying that the prog has stopped working and no output appears. I want to put the name in user[n].name, the phone number in user[n].phoneNumber and the address in user[n].address
View 1 Replies
View Related
Jan 25, 2013
I have a .txt file that contains, together with a few characters, columns of values that I want to save in different files like is written in the program (file 1, file2, file3 - a with x, b with y, c with z). The pattern of the source text file is like this:
known_vector frame1 151 65 0 frame2 151.000763 64.538582 0.563737
known_vector frame1 152 65 0 frame2 152.000702 64.542488 0.560822
known_vector frame1 153 65 0 frame2 153.000671 64.546150 0.558089
Until now I could manage to split the files, but the output gives me only zeros. First the program count the number of lines of the read text file, then it should display the desired columns of double values in three other .txt files.I've got for the three .txt files columns like this:
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
View 2 Replies
View Related
May 15, 2013
I want to read the contents of a file block (512 bytes) by block using low I/O read statements. Each record is 64 bytes long and has a pre-defined structure. The first 4 bytes are an unsigned integer; the next 20 bytes are ascii text, etc.
I have a buffer which I can access with buf[0] to buf[63] to read the first record and then buf[64] to buf[127] for the second, etc. However, I was wondering how to map a record so that I can refer to an integer as an integer and a float as float, etc. I can't create a struct and move the 64 bytes to it, as I will have alllignment/padding problems.
What is the standard way to deal with records in C?
View 5 Replies
View Related
Jul 2, 2014
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
// Function prototype
void getScore(int& score, ifstream& inFile);
void calcAverage(int s1, int s2, int s3, int s4, int s5, int lowest);
[Code] ....
The program is suppose to report back the lowest number of 5 grades in a file..then it is suppose to report the average of remaining 4 higher scores..It appears to be reporting the correct average which tells me that it is reading the file and dropping the lowest score but it does not report back the lowest score first.
View 12 Replies
View Related
Oct 21, 2014
Program to read in 15 numbers and display them as follows //each number on a separate line
Code:
# include <stdio.h>
# define MY_ARRAY 15
int main(){
int i ;
printf("please enter 15 numbers
[Code] ....
Error that i get from compiler:
Error E2062 array1.c 14: Invalid indirection in function main()
Error E2062 array1.c 19: Invalid indirection in function main()
both pointing to the separate "scanf"
View 6 Replies
View Related
Oct 22, 2014
The problem states that i need to accept any pin number between "00000" and "99999". I need to read the PIN the user enters as an integer. The problem is that if the PIN is read as an integer, the PIN "01111" will be "1111" which is invalid and the pin "00001" would be read as "1" which is also invalid. How would I go about fixing this problem for PIN numbers that start with a "0"? Again I cannot read the PIN as a char array or string.
View 2 Replies
View Related
May 21, 2014
I want to read a folder that contains large number of tif files. (say 1000 tif images) requirement is to read all files and store in a array/array pointer.
View 1 Replies
View Related
Nov 10, 2014
So I tried creating a test code for reading a negative number and positive number but whenever I enter a negative number it read it as being positive.
#include <stdio.h>
#include <iostream>
#include <iomanip>
[Code].....
PS: I am using char over int because the program that I am testing for requires me to use 8 bit variable.
View 2 Replies
View Related
Aug 3, 2012
Having an issue with the following code. I read in a decimal value from a text file, use atof (or strtod, either gives the same error) to convert the read value into a floating point number. When putting the output of atof in a double, it works fine. However when putting the output of atof into a float, the decimal places get lost. Putting the result in a double, then into a float gives the same result. This only happens when using getline.
I've tried using temp arrays to put the result of pch in, sprintfs and such to try and work around it, but whenever a value originates from the getline command, the float value always loses decimal places. I've also tried varying the precision in the printf statement, but its always the same. When I write the float result to a file via FILE.write in binary mode, the result comes out without the decimal places when I read it back in later.
The simple solution is to not use float and use double, but there are a number of reasons I'm using float to begin with and don't want to change that.
Side note, this code works fine on a windows machine, the error is coming from using g++ on a mac.
Code:
printf("Reading from File
");
ifstream FILE(argv[2],ios::in);
char BU[128];
char *pch;
[Code] ....
Code output :
Reading from File
338769.0109
338769.010900
338769.000000
View 4 Replies
View Related
Jan 13, 2013
I have an assignment where I need to read in a phone number into any array and I can't use the string data type. Assuming I need to use the getline function, how do I do this? I'm guessing it's with the cstring or .c_str() functions? I don't know.
View 4 Replies
View Related
Apr 6, 2014
My C programming class wants us to write a program to read integers into an array, sort the numbers and print out the occurrence of each number. I've tried everything that I can think of but the core dump is still occurring.
void countValues ( FILE *inf, int list[], int size ); /* Function prototypes. */
void printFrequencies( const int list[], int size );
int main (void) {
int status = EXIT_SUCCESS; /* defaulting status to success. */
FILE *inf = fopen( "numbers.txt", "r" ); /* input data file */
[Code] .....
View 6 Replies
View Related
Feb 18, 2015
Basically this is what i need to do. Write a program that reads a number from the keyboard, separates it into its individual digits and prints the digits to screen, each on its own line followed by the same number of stars as itself.
For example, if the number is 2339 the program should print
9 *********
3 ***
3 ***
2 **
So far i have managed to separate the number and have them on different lines, but how to implement the stars onto each line with the number!
My code so far:
int main() {
int n;
printf("number? ");
scanf("%d", &n);
while (n > 0) {
printf("
%d
[Code]...
View 4 Replies
View Related
Mar 24, 2014
write a program in c to read a sequence of N integers and print the number that appears the maximum number of times in the sequence.
View 1 Replies
View Related
Dec 18, 2013
I have to communicate between two laptops using USB-to-Serial adapter. I have written 2 programs one for sending and another for receiving. Programs were written in both C and C# programming languages.
Using C language: I am able to successfully communicate using C-Programs mentioned below. But the problem is speed. It takes around 1 hour(60min) for just to pass 150MB. improving the performance of this programs...I also mention some comments along with programs for self understanding.Sender File on laptop with serial port :
Code:
#include <stdio.h>
#include <bios.h>
#include <conio.h>
}
[code]....
The above 4 programs behaves as, sender send a character and receives an ack for every character. I have followed this approach, bcoz other approaches were not working fine (in the sense the complete data is not sent, the amount of data sent is not judgeable, bcoz it will different every tym). when i used this approach it worked fine.
View 6 Replies
View Related
Mar 15, 2013
Wondering why I cannot communicate with my microcontroller dspic33 with the Hyperterminal program. In the sample test code, I also cannot use printf. They have it set up differently and I am wondering if it is possible to redirect the output of the printf, scanf functions to the port I am using?
View 3 Replies
View Related
Jan 19, 2015
I am trying to make a project using arduino to control several power surces by time, i don't want to have an lcd, that would be easyer but i don't have enought space on my project, i want to set the time and the timing for the relays via Serial
Of curse i could set it using the serial monitor on the arduino ide, but i want to make a simple program to make the pc comunicate with the arduino and make it simpler to set the time and similar stuff. How to use one of my usb ports to print and read serial data?
View 1 Replies
View Related