Im trying to scan in a txt file with a string of numbers.
t.txt
123
223
323
File *f = fopen(t.txt, r)
while (i != 3){
for (int j = 0; j < 3; j++){
fscanf(f, %1c, &grid[i][j]);
}
i++;
}
But it prints a segment fault.
Tips, Expertise, Articles and Advice from the Pro's for Your Website or Blog to Succeed
Im trying to scan in a txt file with a string of numbers.
t.txt
123
223
323
File *f = fopen(t.txt, r)
while (i != 3){
for (int j = 0; j < 3; j++){
fscanf(f, %1c, &grid[i][j]);
}
i++;
}
But it prints a segment fault.
Ive been trying to use the fscanf function to read a txt file containing a single number into a ptr:
(file.txt)
1
File *fPtr=fopen(file.txt, r)
int r;
fscanf(fPtr, %d, &r);
I keep getting a segmentation fault, after running it though the program compiles. It happens pretty much any other way I try to call Fscanf too.
Hello anyone know how encode a script like this? <?php
$_obfuscatedFF66756E6374696F6E = function ($f, $d) {
$lines = @file($f);
$c = @count($lines) - 2;
$lines[$c] = @strtok($lines[$c], "\");
$head = (int) @base64_decode(@strtok(@end($lines), "\")) - 161803;
$code = @join("", @array_slice($lines, $head, -1));
$code = @openssl_decrypt($code, "AES-128-CBC", "ioncube is so easy to decode these days...", false, "1!2@3#4$5%6^7&8*");
$idx = @base64decode(@strtok("\"));
if (!defined("__FILE" . $idx . "")) {
define("FILE" . $idx . "", $f);
define("DIR" . $idx . "",
retur
retur
?>
Type the next higher prime following the number entered in the console. in c#
Create three classes the Calculation class, Conversion class and Menu Class.
The Conversion class should have the following methods.
double KMToMiles(double distance)
double MilesToKM(double distance)
double FeetToMetres(double distance)
double MetresToFeet(double distance)
double KgToPounds(double weight)
double PoundsToKg(double weight)
double CelciusToFahrenheit(double temperature)
double FahrenheightToCelcius(double temperature)
The Calculation class should have the following methods.
int SumOfSeries(int start, int end, int incr)
int SumOfArray(int data[], int size)
int ProductOfSeries(int start, int end, int incr)
int ProductOfArray(int data[], int size)
e.g. SumOfSeries(10,20,2) should produce the answer 90
Hint : 10+12+14+16+18+20
Similary ProductOfSeries(100,200,50) should produce 3,000,000
Hint : 100x150x200 = 3,000,000
The Menu class should have the following methods.
void displayMainMenu()
void displayConversionSubMenu()
void displayCalculationSubMenu()
void displayConversionLengthSubmenu()
void displayConversionWeightSubmenu()
void displayConversionTemperatureSubmenu()
The menu class methods should display the options available under each selected menu.
e.g. The displayConversionSubMenu() method should display the following.
Conversion Sub Menu
statement: write a code in which user first select what type calculator they want to use. Simple or scientific and on that basis they do the calculations.
I have written the following code but it is not running. I am unable to figure out the problem. Please anybody help!!
#include <iostream>
#include <string.h>
#include <conio.h>
#include <math.h>
using namespace std;
int main()
{
int input;
cout << "CHOOSE BETWEEN SCIENTIFIC AND SIMPLE CALCULATOR:" << endl;
cout << "[1] Scientific" << endl << "[2] Simple" <<endl;
cin >> input;
switch(input)
case '1':
float a,b;
int z;
void Power(float,float);
void Sine(float);
void Square(float);
void Cos(float);
void Tan(float);
void Log(float);
void Baselog(float);
cout<<"WHAT YOU WANT TO FIND: "<<endl;
cout<<"Press '1' for Power: "<<endl;
cout<<"Press '2' for Sin: "<<endl;
cout<<"Press '3' for Square: "<<endl;
cout<<"Press '4' for Cos: "<<endl;
cout<<"Press '5' for Tan: "<<endl;
cout<<"Press '6' for Log: "<<endl;
cout<<"Press '7' for Base Log: "<<endl;
cin>>z;
switch(z)
{
case 1:
cout<<"Enter the Number for Calculating its Power: "<<endl;
int a;
cin>>a;
cout<<"Enter the Power for a Number: "<<endl;
int b;
cin>>b;
Power(a,b);
break;
case 2:
cout<<"Enter the Number for Calculating SIN: "<<endl;
cin>>a;
Sine(a);
break;
case 3:
cout<<"Enter the Number for Calculating Square: "<<endl;
cin>>a;
Square(a);
break;
case 4:
cout<<"Enter the Number for Calculating COS: "<<endl;
cin>>a;
Cos(a);
break;
case 5:
cout<<"Enter the Number for Calculating TAN: "<<endl;
cin>>a;
Tan(a);
break;
case 6:
cout<<"Enter the Number for Calculating LOG: "<<endl;
cin>>a;
Log(a);
break;
case 7:
cout<<"Enter the Number for Calculating LOG WITH BASE 10: "<<endl;
cin>>a;
Baselog(a);
break;
}
getch();
}
void Power(float x,float y)
{
float p;
p = pow(x,y);
cout<<"Power: "<<p;
}
void Sine(float x)
{
float s;
s = sin(x);
cout<<"Sin: "<<s;
}
void Square(float x)
{
float sq;
sq = sqrt(x);
cout<<"Square of a Given Value is: "<<sq;
}
void Cos(float x)
{
float c;
c = cos(x);
cout<<"COS: "<<c;
}
void Tan(float x)
{
float t;
t = tan(x);
cout<<"TAN: "<<t;
}
void Log(float x)
{
float l;
l = log(x);
cout<<"Natural Logarithm: "<<l;
}
void Baselog(float x);
float bl;
bl = log10(x);
cout<<"LOG with Base 10: "<<bl;
break;
case '2':
int num1,num2;
char op;
cout << "Enter an operator (+, -, *, /): ";
cin >> op;
cout << "Enter two numbers: " << endl;
cin >> num1 >> num2;
if(op=='+') {
cout << num1 << " + " << num2 << " = " << num1 + num2; }
else if(op=='-') {
cout << num1 << " - " << num2 << " = " << num1 - num2; }
else if(op=='*') {
cout << num1 << " * " << num2 << " = " << num1 * num2; }
else if(op=='/') {
cout << num1 << " / " << num2 << " = " << num1 / num2; }
else{
cout << "Error! The operator is not correct";
}
break;
return 0;
}
Hi, I'm searching for a way that let run a event without need, that specific form to be open, and also save thing.
I explain better, the performclick will only fire if that specific form it's open, I'm searching a way to do this on background.
This is the code of where performclick will fire (thanks to a timer)
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Dim value As Integer = maxVal
If Not IsNumeric(Label10.Text) Then
Label10.Text = maxVal.ToString
End If
Integer.TryParse(Label10.Text, value)
If value >= 1 And value <= maxVal Then
value -= 1
Label10.Text = value.ToString
Else
If value <= 0 Then
Form11.Button5.PerformClick()
Timer1.Stop()
Label10.Text = maxVal.ToString
End If
End If
Catch ex As Exception
End Try
End Sub
This is the form11's button_5 code
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Try
For i As Integer = 0 To ComboBox3.Items.Count - 1
ComboBox2.SelectedIndex = i
Dim d As DateTime = DateTime.Now
Dim parsedate As DateTime = ComboBox2.Items(i).ToString
Dim d2 As DateTime = DateTime.ParseExact(parsedate, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture)
Dim ts As New TimeSpan((d - d2).Ticks)
Dim dysdiff As Integer = ts.TotalDays
Dim cbNum As Integer = 365 - dysdiff
ComboBox3.Items(i) = cbNum.ToString
Dim lstname As String
lstname = ListBox1.Items(i).ToString()
If cbNum <= 10 AndAlso cbNum >= 1 Then
NotifyIcon1.ShowBalloonTip(3000, "test", lstname & " have " & cbNum & " days left before will get delete", ToolTipIcon.None)
End If
Next
Catch ex As Exception
End Try
End Sub
How to make diamond with the help of loops
Hi, I like to ask for a clarification about it. I have combobox.items(i) that go trough a for next loop for each index I need to check if its content (number) will be >=1 or <=10. Now I tried this one, but I know where the error might be, the + " Days" combination that it's a string and when checking in the if statement the text it give me an error of course. It's there any tip to check only a number in a integer + string combination on an if?
In case I can delete the + " days" and put it in an label so the combobox will be filled only with the integer part, and the if can work (if I'm right)
This is the part of code
ComboBox3.Items(i) = (365 - dysdiff).ToString + " Days"
If ComboBox3.Text.ToString >= 1 <= 10 & " Days" Then
MsgBox("post old", MessageBoxButtons.OK)
Else
End If
Next
Hi, like title, I have a timer, that when reach 0 will fire event on another form, then timer restart but when reach 0 nothing happen. how can I achieve this?
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim value = CInt(Label10.Text)
If value >= 1 And value <= 30 Then
value -= 1.ToString
Else
If value >= 0 Then
Form11.Button5_Click(sender, e)
Timer1.Stop()
End If
End If
End Sub
Hi, how can I make sure that all the datetime stored previously by user input will be updated in a cycle for?
I explain better the structure
Combobox2 <----- is where list of datatime are previously stored
Combobox3 <------- is where remaining time is given by a substraction of two dates, stored in days remaing.
The fact, is now that these values are only stored and doesn't change with time passing by.
This is my code
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
For i = 0 To ListBox1.Items.Count
Dim d As DateTime = DateTime.Now
Dim d2 As DateTime = ComboBox2.SelectedItem(i)
Dim dysdiff As String = (d - d2).Days.ToString()
ComboBox3.SelectedItem(i) = 365 - dysdiff & " Days"
Next
End Sub
Hi, how can I clean all saved settings in my.settings ? Do I need only to put
my.settings.[name].clear() or a My.settings.reset() can do a good job for all the user setting added into the program?
Also how can I add an exception if there is nothing in that setting or all settings? Can I put like
the isnullorempthy and referring it to that particular setting?
If ask = Msgboxresult.Yes then
my.settings.[name1].clear()
my.Settings.reset()
if ask = msgboxresult.no then
end if
Hi, I have a issues, in this code I have a countdown with function declared, the issues now is that, if starting the time with only seconds timer go well but if the timer go to one minute if button is clicked timer suddently stop. Is there anything wrong with the code?
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Label5.Text = 0 AndAlso Label8.Text = 0 AndAlso Label7.Text < 59 Then
Label7.Text = Label7.Text - 1.ToString
If Label5.Text = 0 AndAlso Label8.Text = 0 AndAlso Label7.Text = 0 Then
Timer1.Stop()
MsgBox("timer out", MessageBoxButtons.OK)
End If
If Label7.Text = 0 AndAlso Label8.Text > 1 Then
Label8.Text = Label8.Text - 1.ToString
Label7.Text = 59
ElseIf Label5.Text >= 0 AndAlso Label8.Text >= 0 AndAlso Label7.Text = 59 Then
Label7.Text = 59
Label8.Text = 59
Label7.Text = Label7.Text - 1.ToString
Label8.Text = Label8.Text - 1.ToString
Label5.Text = Label5.Text - 1.ToString
End If
End If
End Sub
i have initialized the elements of the array by reading the strings from a file, however when I call the sort function, either the program crashes or it just outputs NULL. What could be a more efficient way to store data from a file?
the file that I have opened contains the following text:
"
ppp zaeem na2 lun
pti farea na1 balla
"
#include <iostream>
#include <string>
#include <stdlib.h>
#include <Conio.h>
#include <cstdlib>
#include <string>
#include <string.h>
#include <cstring>
#include <fstream>
using namespace std;
class candidate
{
public:
string party;
string name;
string constituency;
string symbol;
candidate()
{
party = "";
name = "";
constituency = "";
symbol = "";
}
};
candidate *candi = new candidate[3];
int size = 0;
void read_into_array()
{
int i = 0;
string name, party, consti, symb;
ifstream a("new.txt");
if (!a)
cout << "file not found." << endl;
else
{
a >> party >> name >> consti >> symb;
while (!a.eof())
{
candi[i].party = party;
candi[i].name = name;
candi[i].constituency = consti;
candi[i].symbol = symb;
a >> party >> name >> consti >> symb;
size++;
i++;
}
a.close();
}
}
class voter
{
public:
void show_all_candidates()
{
for (int i = 0; i < size; i++)
{
cout << "Candidate's Name: " << candi[i].name << endl;
cout << "Candidate's Constituency: " << candi[i].constituency << endl;
cout << "Candidate's Party'" << candi[i].party << endl;
cout << "Party Symbol: " << candi[i].symbol << endl;
}
}
void sort_by_name()
{
for (int i = 1; i < size; i++)
{
for (int j = 1; j <size-i; j++)
{
string temp=" ";
if (candi[j].name > candi[j + 1].name)
{
temp=candi[j].name;
candi[j].name = candi[j + 1].name;
candi[j + 1].name = temp;
temp=candi[j].constituency;
candi[j].constituency = candi[j + 1].constituency;
candi[j + 1].constituency = temp;
temp=candi[j].party;
candi[j].party = candi[j + 1].party;
candi[j + 1].party = temp;
temp=candi[j].symbol;
candi[j].symbol = candi[j + 1].symbol;
candi[j + 1].symbol = temp;
}
}
}
}
};
int main()
{
voter obj_voter;
read_into_array();
obj_voter.sort_by_name();
obj_voter.show_all_candidates();
// obj_voter.sort_by_name();
}
Like title, more particulary, I have two textbox when user put links when finished the result will be on the second one with some default string in the 0 index of the counter and after the exiting of the loop. My question is how I can make that even the last line will be readed in the for loop? Because I was thinking that the problem will be in the temparray=textbox1.Lines
tempArray = TextBox1.Lines
For counter = 0 To tempArray.Length - 1
If counter = 0 Then
tempArray(0) = cbname2
ElseIf counter = 1 Then
tempArray(1) = "~!" & "img(" & tempArray(counter) & ")"
ElseIf counter >= 2 Then
tempArray(counter) = "img(" & tempArray(counter) & ")"
End If
TextBox2.Lines = tempArray
Next
TextBox2.Text &= vbCrLf & "!~" & " ~~~"
End Sub
Hi all, I have created an Event handler to a function for clicking a generated button, now when this button is clicked need to paste in a textbox the Combobox.seleteditem (that it's a string. Each generated one (Combobox, textbox, button) will have a selected index of the Combobox that it's different, but that is not the problem because I put it in an if, the issues it's that I can't put inside this sub all the three-component. After all, it tells me that the windows form button cannot be a textbox, etc. Do I need to put another two event handlers for textbox and Combobox? (The code below it's a workaround, but I Like to do this with a button)
Public Sub btn_Click(sender As System.Object, ByVal e As System.EventArgs)
'Dim btn As New Button
'btn = CType(sender, Button)
'Dim txt As New TextBox
'txt = CType(sender, TextBox)
Dim cbx As New ComboBox
cbx = CType(sender, ComboBox)
TextBox4.Text += cbx.SelectedItem.ToString & vbCrLf
End Sub
#include<iostream>
using namespace std;
class Sports
{
public:
int tennis;
int badminton;
int cricket;
int setA[20],setB[20],setC[20];
int ab[20],bc[20],ca[20],abc[20];
int n1,n2,n3,n4=0,total;
void accept(); // method for accept the input
void intersection(); //method for calculate intersection
void display(); //method for display intersections
};
void Sports :: accept()
{
cout<<"Enter the total number of players who play Tennis: "<<endl;
cin>>tennis;
cout<<"Enter the student roll no who play Tennis "<<endl;
for(int i=0; i<tennis; i++)
cin>>setA[i];
cout<<"Enter the total number of players who play Badminton: "<<endl;
cin>>badminton;
cout<<"Enter the student roll no who play Badminton "<<endl;
for(int i=0; i<badminton; i++)
cin>>setB[i];
cout<<"Enter the total number of players who play cricket: "<<endl;
cin>>cricket;
cout<<"Enter the student roll no who play cricket "<<endl;
for(int i=0; i<cricket; i++)
cin>>setC[i];
}
void Sports :: intersection()
{
// Logic for intersection SET-A and SET-B
for(int i=0;i<cricket;i++)
{
for(int j=0;j<badminton;j++)
{
if(setA[i]==setB[j])
{
ab[n1]=setA[i];
n1++;
}
}
}
// Logic for intersection SET-B and SET-C
for(int i=0;i<badminton;i++)
{
for(int j=0;j<cricket;j++)
{
if(setB[i]==setC[j])
{
bc[n2]=setB[i];
n2++;
}
}
}
// Logic for intersection SET-C and SET-A
for(int i=0;i<cricket;i++)
{
for(int j=0;j<tennis;j++)
{
if(setC[i]==setA[j])
{
ca[n3]=setC[i];
n3++;
}
}
}
//logic for A union B union C
for(int i=0;i<tennis;i++)
{
for(int j=0;j<badminton;j++)
{
for(int k=0;k<cricket; k++)
{
if(setA[i]==setB[j] && setA[i]==setC[k])
{
abc[n4]=setA[i];
n4++;
}
}
}
}
total=tennis+badminton+cricket-n1-n2-n3+n4;
}
void Sports :: display()
{
//logic for print intersection of tennis and Badminton
cout<<"\nIntersection of SET-A and SET-B: ";
for(int i=0; i<n1; i++)
cout<<ab[i]<<" ";
//logic for print intersection of Badminton and Cricket
cout<<"\nIntersection of SET-B and SET-C: ";
for(int i=0; i<n2; i++)
cout<<bc[i]<<" ";
//logic for print intersection of Cricket and Tennis
cout<<"\nIntersection of SET-C and SET-A: ";
for(int i=0; i<n3; i++)
cout<<ca[i]<<" ";
// logic for print intersection of Tennis and Badminton and Cricket
cout<<"\nIntersection of SET-A and SET-B and SET-C: ";
for(int i=0; i<n4; i++)
cout<<abc[i]<<" ";
// logic for print total number of students in a class
cout<<"\nTotal number of students in class are : "<<total;
}
int main()
{
Sports s;
s.accept();
s.intersection();
s.display();
return 0;
}
If you download multiple files with the same name, a number is automatically added to the file name, for example: filename(1), filename(2) etc..
What I am trying to do is when I am creating a name and there is already a same one, the name I create to appear in the list as: name(1), name(2) etc.
This is the code that I use now that only creates: name and name (1), then I get this error when trying to create the next same name, example: name (1) already exists in your list., but I shouldn't get that error and should create the next name in the list: name (2) etc..
$deviceUser = "07NAV" . $var;
$sameNames = $mktApi->comm("/ppp/secret/getall", array(
".proplist" => ".id",
"?name" => $deviceUser
));
$i = 0;
if($sameNames) {
$i++;
$mktApi->comm("/ppp/secret/add", array(
"name" => $deviceUser . " ($i)",
"remote-address" => $IPs[$ipAddress],
"password" => $devicePass,
"service" => "pppoe",
"comment" => $fullAddress
));
}
Also, I've tried using this one:
$i = 0;
if($sameNames) {
for($i = 0; $i < 99999; $i++) {
$i++;
$mktApi->comm("/ppp/secret/add", array(
"name" => $deviceUser . " ($i)",
"remote-address" => $IPs[$ipAddress],
"password" => $devicePass,
"service" => "pppoe",
"comment" => $fullAddress
));
}
}
but when I create only one name in my list, automatically creates X names and I do not want that.
I've been searching for help on other communities too and somebody provided me this code, but I still get the same error ("user with same name already exists"):
// Start your update here:
$i = 0;
$deviceUser = $deviceUserOriginal = "07NAV" . $var;
$sameNames = false;
do {
// First - check if a dupe exists...
$sameNames = $mktApi -> comm("/ppp/secret/getall", array(
".proplist" => ".id",
"?name" => $deviceUser
));
// Second - update and prepare for rechecking ...
if($sameNames === true) {
$i ++;
$deviceUser = $deviceUserOriginal . "(". $i .")";
}
// Finally, below, if check failed, cycle and check again with the new updated name...
}
while($sameNames === true);
// Finally, tidy up.
// If you need the original value of $deviceUser you can retain it.
unset($i, $deviceUserOriginal);
// Continue your script here:
$mktApi -> comm("/ppp/secret/add", array(
"name" => $deviceUser,
"remote-address" => $IPs[$ipAddress],
"password" => $devicePass,
"service" => "pppoe",
"comment" => $fullAddress
));