Shouldn't this
scanf("%s", &employeeIDNew);
be
scanf("%s", employeeIDNew);
Shouldn't this
scanf("%s", &employeeIDNew);
be
scanf("%s", employeeIDNew);
You can set the delimiter for getline().
istream& getline (istream& is, string& str, char delim);
Please check out this link
http://www.cplusplus.com/reference/string/string/getline/
Are you sure the datafile is in the same folder as the executable.
Did you pass std::endl or "\n" to std::cout?
Try running this program with your data.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv)
{
ifstream names;
names.open("P25.txt");
string data;
while(names >> data)
{
cout << "You read->" << data << "<-into data!" << std::endl;
}
names.close();
return 0;
}
Yes, you will searching for the element contained in the array std. If you need to search id in the array std then you could loop through std and check each id.
size_t i = 0;
for (; i < 100; ++i)
{
if (std[i].id == some_int)
{
//do something here
}
}
Well this is how you access an element of std[100] and get its elements.
std[searchid].id
std[searchid].name
std[searchid].fatherName
std[searchid].motherName
Try reopening the input file or setting the file position back to the beginning with fseek() on line 22.
If you insists on breaking out of the loop immediately then you should use break.
Something like this...
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int employeeNumber = 0;
while( true )
{
cout << "\nEmplyee Number: ";
cin >> employeeNumber;
cout << endl;
if ( employeeNumber == 0 ) break;
while( true )
{
cout << "Inner loop\n";
//do something here
}
}
cout << "Done" << endl;
return 0;
}
Well what do you need help with? Please post the code you attempted and highlight any sections and explain the problems.
I would have to say that you need a flagging system which marks a integer element when its been counted.
Are you sure this is C?
for(int i = 0; i < 10; i++)
{
...
}
Looking at your code I find that you have to make a decision. Do you want to calculate the average once and store the value in the structure Student or do you want to calculate the student average each time you need it.
void Print_List(Student List[], int Size)
{
cout <<left << fixed << setprecision(2) <<showpoint <<endl ;
cout << setw(19) << "Name"
<< setw(18) << "ID"
<< setw(18) << "Average"
<< setw(16) << "Grade" << endl;
cout << "=============================================================" << endl;
for(int i = 0; i < Size;i++)
cout << setw(19) << List[i].LastName +", "+ List[i].FirstName
<< setw(18) << List[i].Id
<< setw(20) << calcAverage(List[i])//I use the return value here but it also stores the result in student
<< List[i].Grade << endl;
}
So what is a ArrayList?
You two errors on line one
for (index = 1; index < SIZE; ++);
for (index = 1; index < SIZE; ++index)
{...}
No. You have to take the source code over to a Windows compiler and recompile it into a Windows exe.
int chdir(const char *path);
You can use chdir() which is in the unistd.h header file.
You have this
gcc -std=c++11 -std=c++0x -W -Wall tt1.cpp
but should it be
g++ -std=c++11 -std=c++0x -W -Wall tt1.cpp
No, I want to inistialize the vector from inside the constructor initialization list the goal is not to use the constructor body too, only from the list
I thought I was doing that in my example.
Are you talking about something like this?
#include <iostream>
#include <vector>
#include <iterator>
template <class T>
class test
{
public:
test(T a[], size_t s):vec(a, a + s ) {}
void display_vec() const
{
std::copy(vec.begin(), vec.end(), std::ostream_iterator<T>(std::cout, " "));
}
private:
std::vector<T> vec;
};
int main(int argc, char** argv)
{
unsigned long mya[] = {1,4,5,7};
test<unsigned long> you(mya, sizeof(mya)/sizeof(unsigned long));
you.display_vec();
return 0;
}
Are you looking for a default constructor which will initialize the std::vector member with the values 1, 4, 5 via the constructor initialization list without embracing the C++11 features?
Here's a correction implementing some of the changes mentioned above
#include <iostream>
class Base
{
public:
Base() {}
~Base() {}
void doSomrthing() {}
};
class MyCLass : public Base
{
std::string name;
public:
MyCLass();
~MyCLass();
void init();
};
MyCLass::MyCLass()
{
init(); //runtime error occurs with this line
}
void MyCLass::init()
{
name = "MyClass";
doSomrthing();
}
int main()
{}
Could it be this
Class
Please note the uppercase C
Or could it be the missing semi-colon here
class Base
{
Base();
~Base();
void doSomrthing();
}
Or here
Class MyCLass : public Base{
std::string name;
MyCLass();
~MyCLass();
void init();
}
Are you having problems with the ternary operator?
http://msdn.microsoft.com/en-us/library/e4213hs1%28v=vs.71%29.aspx
Are you looing for something like this?
#!/usr/bin/perl
use warnings;
use strict;
use autodie qw/open close/;
print "Enter input filename->";
chomp(my $ifilename = <STDIN>);
open(my $IFILE, "<", $ifilename);
while ( <$IFILE> )
{
chomp;
my @data = split(/\t+/, $_);
print "@data\n" unless ( $data[3] eq $data[4] )#print this to another file
}
close($IFILE);
__END__
Since your using warnings and strict you should use my.
my $filesize = -s $filename;
Should you be using \ here
"C:\Users\bt\Desktop\perl_files";
Shouldn't it be
"C:/Users/bt/Desktop/perl_files";
I think you can the rest here
This link will show you how to get file size
http://perlmeme.org/faqs/file_io/filesize.html
You'll have to elaborate on date. Do you mean creation data or last accessed date or last modified date?
Try this
my @files = sort { $a cmp $b } readdir(DIR);
I tried this and it worked.
#!/usr/bin/perl
use strict;
use warnings;
my $dir = 'directory_path';
opendir(DIR, $dir) or die $!;
foreach( sort { $a cmp $b } readdir(DIR))
{
next if (/^\./);
print $_,"\n";
}
closedir(DIR);
exit 0;
Right click on the file in question and select properties. The properties window should have a field 'Full File Path'. If your looking to list the files for the entire project then try the main menu option Edit->Find and choose the proper file name patterns.
Well you could parse the c-string with strtok.
player->draw(s); //errors are these 3 lines, s is an undeclared identifier
So where is s defined?
Try something like below:
#include <stdio.h>
int main()
{
size_t i = 0;
union a
{
int i;
char ch[sizeof(int)];
};
union a u;
for (i = 0; i < sizeof(int); ++i)
{
if (i == 0)
u.ch[i] = 1;
else
u.ch[i] = 0;
}
printf("%d %d %d\n",u.ch[0],u.ch[1],u.i);
return 0;
}
How are your integers stored? Big or small endian? Also, are your integers 2 or 4 bytes?
Well 9 divides into 1 zero times with 1 left over.
Because goto can have devastating results on your program and program flow its frowned on. If you really need to jump all over your program try a safe function like longjmp().
void longjmp (jmp_buf env, int val);
int setjmp ( jmp_buf env );
The error message tells it all. The case needs to be a constant...Like
1,2,3,4,5...or
#define one 1
const unsigned long two 2;
switch(angle)
{
case:1
{}
case:two
{}
}
I think you should consider a few problems with your approach.
1. What if your pointer, points to dynamic memory that's been freed.
2. What if your pointer, points to memory on the stack that's been released.
You could use the static keyword but I would create the array on the heap.
int* Bar(){
int * array = new int[2];
array[0] = 1;
array[1] = 2;
return array;
}
Just remember that you have to track and maybe delete [] this array.
You might want to put 'system("pause")' before return 0.
Yes, I'm surprised your compiler allowed it. The assignment operator must return a reference to the object.
try
std::vector<Rab> items;
I tried this and my compiler didn't complain.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class GameUnit {
public:
string GetName() {return Name;}
protected:
string Name;
};
class Player {
public:
void ListUnits();
protected:
vector<GameUnit*> MyUnits;
};
void Player::ListUnits() {
for(unsigned int i=0; i<MyUnits.size(); i++) {
cout<<MyUnits[i]->GetName()<<"\n";
}
}
int main()
{
return 0;
}
I am pretty sure I can also achieve the same now, but not unless I can pass two.exe a pid and a pointer.
(
Sounds like your accessing the parent or client address space via its pid and a pointer which sounds like your processes may not be sharing an address space.
Note: I have programmed on Windows system infrequently, so I'm ignorant of its functionality.
I was under the impression that a child process shares memory space.
I pass an int pointer to one app at runtime via command line and the second app modifies it. Since both apps know the address they can share the variable between them.
At least that is how I thought it to work, I have certainly done this in another scripting language, passing a whole array of pointers.
No a child process(at least a child process in Linux) has its own address space so passing pointers from its parent will be meaningless.
Maybe you could pass along some specifics of what your trying to do.
It doesn't make sense to pass memory pointers between address spaces.
And the last one
char * p2 = "Some string";
printf("Unknown (with asterisk): %d\n", *p2);
Unknown (with asterisk): 83
dereferncing a character pointer returns the character pointed to which is 'S' and the numeric(ascii) value of 'S' is 83.
I would say that this is the value of the address held by p3
Unknown (without asterisk): 4210883
Sure:
size->4 size->4 size->0022FF4C size->2293580
~G
I just wanted to make sure you weren't truncating anything..
Now lets look at
int * p3 = "47352";//assign to pointer p3, the pointer that points to "47352"
Unknown (with asterisk): 892548916
*p3 produces 892548916
now 892548916 has a hex value of 0x35333734 which has ascii values
0x35 = '5'
0x33 = '3'
0x37 = '7'
0x34 = '4'
notice that p3 points to "47352" which is an int pointer and int are four bytes on your system so your getting the first four characters of the string "47352".
Could you post the results of running this code.
#include <stdio.h>
int main()
{
int x;
fprintf(stdout, "size->%lu\n", sizeof(void*));
fprintf(stdout, "size->%lu\n", sizeof(int));
fprintf(stdout, "size->%p\n", (void*)&x);
fprintf(stdout, "size->%d\n", (int)&x);
return 0;
}
First off your missing two includes
#include <stdlib.h>
#include <string.h>
Also this function
void add(char *firstName, char *lastName, int *exam) {
struct node *newnode = malloc(sizeof(struct node));
newnode->firstName = firstName;//must use strcpy(newnode->firstName, firstname)
newnode->lastName = lastName;//must use strcpy(newnode->lastName, lastName)
newnode->exam = exam;//actually not sure what your doing here
newnode ->next = NULL;
if (head == NULL) {
head = newnode;
}
else {
struct node *cur = head;
while (cur->next != NULL) {
cur = cur->next;
}
cur->next = newnode;
}
}