Reading Data from file using read function in c++ - read-data

void fileRead()
{
student s22;
fstream out;
out.open("ABC.txt",ios::in);
while(!out.eof())
{
out.read((char *)&s22,sizeof(s22));
cout<<s22.roll_no<<"\t"<<s22.name<<"\t\t"<<s22.marks<<"\t"<<endl;
}
}
When I try to read data from file using read function in C++ then it return last record 2 times.
Output like this:
11 Ram 70
12 Mohan 80
12 Mohan 80
I do not understand this problem. Please help me to solve this.

Related

Fibonacci in swift playground [duplicate]

This question already has answers here:
Simple Swift Fibonacci program crashing (Project Euler 2)
(2 answers)
using for loop for fibonacci series to print values it will print up to 47 values above that it shows error [closed]
(1 answer)
Fibonacci Calculator stack overflows at 93nd number in Swift [duplicate]
(2 answers)
Closed 4 years ago.
can someone please guide me why this code that i wrote only works until userInput is less than 94 ?
func calculateFibonacciFucntionUntil(userInput: Int) {
var array = [0 ,1]
for i in 2...userInput {
array.append(i)
array[i] = array[i - 1] + array[i - 2]
print(array[i])
}
}
calculateFibonacciFucntionUntil(userInput: 10)
The issue is that Int can only store 64bit numbers (on 64bit platforms) and Fibonacci 95 is bigger than the maximum number that can be stored on 64bits.
Fibonacci 95 is 31 940 434 634 990 099 905, while the biggest number Int64 can hold is 2^63-1 = 9 223 372 036 854 775 807.
You can use Decimal for storing larger numbers than what Int can hold Decimal.greatestFiniteMagnitude is 3.4028236692093865e+165.
However, Swift doesn't have a built-in type for storing arbitrarily large numbers, so if you want to do that you'll either need to use a 3rd party library or implement an appropriate data type yourself.

Want to omit some values from TCP packet

I have successfully created the tcp connection between processing and matlab. I am using oscp5 library for that. I am sending an array containing 3 float values from processing.
But in Matlab, I am getting 5 extra values. Please advise how I can omit these values.
Please note that I can't use another library.
Also, someone suggest me, while creating message, I have assigned it a label "/test". When matlab's server gets the message, it will read this as well as the data in your package as assembled by oscP5. So, I have to teach matlab how to interpret that data. Hence, I need to go to the oscP5 website and review java docs and the source code to understand the packaging format. Here the link
http://www.sojamo.de/libraries/oscP5/
You can see the code below.
-------------Processing Code-------------
import oscP5.*;
import netP5.*;
OscMessage myMessage;
OscP5 oscP5tcpClient;
void setup() {
size(640, 360);
oscP5tcpClient = new OscP5( this, "141.44.219.204", 1234, OscP5.TCP);
}
void draw() {
background(255);
OscMessage myMessage = new OscMessage("test\");
myMessage.add(new float[] {123.2, 134.5, 52.5}); ==>> Sent Message
oscP5tcpClient.send(myMessage);
print(50+sin(a)*40.0);
}
-----------------------------------------------------------------
--------------------------MATLAB Code----------------------------
>> tcpipServer = tcpip('141.44.219.161',1234,'NetworkRole','Server');
>> fopen(tcpipServer)
>> data = fread(tcpipServer, 8 , 'float32')
data =
0 ===>> want to omit
0.0000 ===>> want to omit
0 ===>> want to omit
123.2000
134.5000
52.5000
0.0000 ===>> want to omit
0 ===>> want to omit
>>
-----------------------------------------------------------------

How to read .csv file from a different location in MATLAB?

I'm new to MATLAB, I've been fiddling around to import a .csv file which is on my desktop to MATLAB. I've already tried csvread() function as shown,
M = csvread(C:/Users/XYZ/Desktop/train.csv)
Please help. Thanks in advance.
EDIT:
My data is in the following format:
Id DV T1 T2
1 1 15 3
2 4 16 14
3 1 10 10
4 1 18 18
The csvread method takes a string (i.e. a char type) for the filename. In matlab a char must be expressed inside quotation marks, so this should work:
M = csvread('C:/Users/XYZ/Desktop/train.csv')

DEPLOYED MATLAB FILE DOES NOT START

Please, I have this piece of code that involves saving state of gui (using Doug Hull's) approach.
The problem is the script compiles alright but only pops up and vanishes when I run it, using deploytool. I am using Matlab R2012b.
function savestate3
S.fh=figure('NumberTitle','off',...
'Visible','on','Position',[360 400 450 285],...
'closerequestfcn',{#fh_crfcn});
S.tg(1)=uicontrol(S.fh,'Style','toggle','String','Semester',...
'pos',[15 250 100 25],'val',0,'visible','on');
S.tg(2)=uicontrol(S.fh,'Style','toggle','String','Details',...
'pos',[135 250 100 25],'val',0,'visible','on');
S.ed(1)=uicontrol(S.fh,'Style','edit','String','Edit Text',...
'pos',[250 70 100 25],'visible','off');
S.lb(1)=uicontrol(S.fh,'Style','listbox','String',{'One','Two','Three'},...
'pos',[100 170 100 70],'visible','off');
S.cb(1)=uicontrol(S.fh,'Style','checkbox','Value',1,'String','Check Me',...
'pos',[250 170 100 25],'visible','off');
set(S.tg(:),'callback',{#tg_call,S})
guidata(S.fh,S)
restoreState(S);
function saveState(handles)
state2.editstr=get(S.ed(1),'String');
state2.listval=get(S.lb(1),'value');
state2.checkval=get(S.cb(1),'value');
save state1.mat state2
end
function restoreState(handles)
load 'state1.mat' 'state2'
set(S.ed(1),'string',state2.editstr,'FontSize',12,'FontWeight','bold');
set(S.lb(1),'value',state2.listval);
set(S.cb(1),'value',state2.checkval);
end
function fh_crfcn(varargin)
saveState(S)
delete(S.fh)
end
%TOGGLE OPERATIONS
function []=tg_call(varargin)
%Toggle Operations
[h,S]=varargin{[1,3]};
if get(h,'val')==0
set(h,'val',1)
end
switch h
case S.tg(1)
set(S.tg(2),'val',0)
set(S.ed(1),'visible','on')
set(S.lb(1),'visible','on')
set(S.cb(1),'visible','off')
saveState(S)
case S.tg(2)
set(S.tg(1),'val',0)
set(S.cb(1),'visible','on')
set(S.ed(1),'visible','off')
set(S.lb(1),'visible','off')
saveState(S)
end
end
end
Well I figured this out and still don't know if that is the 'perfect' thing to do.
After compiling, I put the mat file state1.mat in the distr/src folder and it worked.

No overload for method 'Given' takes 4 arguments - specflow

I have installed specflow. And by default I get this scenario to add two numbers. when I build the solution, i get these errors. "No overload for method 'Given' takes 4 arguments". What is that I am missing here? this is the generated file.
public virtual void AddTwoNumbers()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add two numbers", new string[] {
"mytag"});
#line 7
this.ScenarioSetup(scenarioInfo);
#line 8
testRunner.Given("I have entered 50 into the calculator", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
#line 9
testRunner.And("I have entered 70 into the calculator", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 10
testRunner.When("I press add", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line 11
testRunner.Then("the result should be 120 on the screen", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line hidden
this.ScenarioCleanup();
}
For this scenario:
Feature: SpecFlowFeature1
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
#mytag
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
It was a problem of techtalk.specflow.dll version. I had 1.8.1 version which I replaced with 1.9.0 and everything worked ! Thank u for ur suggestions