Jeez, are you posting every question in your assignment?
gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven
jonsca commented: WTG for looking into it more deeply +5
Jeez, are you posting every question in your assignment?
Wow your instructor couldn't find the error..Try this function
long int power(int n,int p)
{
long int ans = n;
int i = 1;
for (; i < p; ++i)
ans *= n;
return ans;
}
Your if - line 58
if (ans3 == 'e')
cout << endl;
probably should be
if (ans3 == 'e')
{
cout << endl;
apple and orange should be enclosed in double quotes..
"orange"
"apple"
I use UBUNTU 10.10
[IMG]http://img835.imageshack.us/img835/5948/screenshotxq.png[/IMG]
Well it should be a matter of downloading the proper package and then using the proper esoteric compile line like
gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
Please note that it uses back tips ` not single quotes '...Back ticks are located on the upper left side of your key board.
That topic you shared with me, I have the same problem i installed those libs and still telling me that he cant find gtk ...
You'll have to give us more info..What distro are you running and what can't find GTK+?
Depends on what your distro packaged it under...For Ubuntu check here.
You could try these two functions
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
yes.
Your reading from a stream that's opened for writing..
So buff is 1024 characters long?
char buff[1024];
Instead of starting at zero and incrementing try starting at columns value and decrementing to zero..
Try
SocketSpace::TCPSocket* SocketSpace::ServerSocket::accept()
Because a returning function will invalidate all its variables, you can't return the address to any of them and expect consistent results...Here's one way to solve your problem using the heap.
#include <stdio.h>
#include <stdlib.h>
#define ARR_SIZE 4
int* foo(void);
int main()
{
int i = 0;
int *ans = foo();
for (; i < ARR_SIZE; ++i)
fprintf(stdout, "ans->%d\n", ans[i]);
free(ans);
return 0;
}
int* foo(void)
{
int i = 0;
int *ar = (int*)malloc(ARR_SIZE * sizeof(int));
for (; i < ARR_SIZE; ++i)
ar[i] = i + 10;
return ar;
}
You have to create your array on the heap in this situation...Returning an address to an array on the stack won't work because the address is invalid as soon as the function returns..
I would investigate the string library's function strcat() and functions like sprintf();
You strcat version and "Stuff" into about...What's 'about'? Can we see its definition?
because your added extern
extern int stack_counter;
extern snode sroot;
This informs the linker that both of these are defined elsewhere.
Line 68, your setting myfile to NULL. It should be myfile == NULL
I'm surprised your compiler didn't complain about that line. I corrected it and the program works now.
The most common way is to overload the operator>>
I tried compiling this but it has errors. You actually got this to compile?
Your not allocating any memory for the member variable name.
This would work better if you define name as a std::string.
Not sure what bit running = 0; is and why you need to take the address and then dereference it...Won't it make more sense to just assign 0 or 1 to running?
Won't this for read twice for each iteration
for(count = 0; count < SIZE && inputFile >> score[count]; count++);
inputFile >> score[count];
Actually on second look what are you doing here? You have a for loop that reads from your file and then you have a read right after the loop...Why? I never saw a file read like that but it works, just tried it.
I found your problem
void minMax(double score[], int SIZE)
{
int count;
int min = score[0];
for(count = 1; count < SIZE; count++);//you have a ; here
{
if(score[count] < min)
min = score[count];
}
cout << "Min =" << min;
}
Here's an example of creating a packed structure using attribute
struct mystr
{
char ca;
unsigned int i;
}__attribute__((packed)) thestr;
I'm pretty sure it has to be like this:
QApplication qApp(&argc, &argv);
Ooops, got GTK+ mixed up with QT4.
Its a warning so it may work...Try casting the offending variable
int X=execvp ("compute",(char* const*)args);
Are you saying your complier is malfunctioning? It won't compile anything?
This is an accepted practice...Don't use any form of
using namespace_name;
in a header file.
Hi Gerard4143,
Thanks for your reply. I'm trying to create a general function that will collect the information from other processes (I have multi-processes; Yeah MPI) this function receive the information form other processes and make an operation (like here SUM) and send back the result to other process and print it.I check the sending and receiving part and they are working properly but when I want to return the value, I have problems.
I guess we can deference a void pinters;for example the following MPI command is similar to what I wanna do;
int MPI_Reduce ( void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm )*sendbuf is input. And *recvbuf is output (void pointer) it return the address of the variable ( that can be int, float, double, etc)
Basically I am doing something similar. Thanks again for your help.
I meant what are you trying to do in the posted code...Its my impression that your trying to pass the addresses of two arrays and then manipulate them inside said function....Note I cast the void pointers to double pointers.
Like so
testit.c
#include <stdio.h>
#include <math.h>
#define MAX 512
void chamaleon (void *sbuf, void *rbuf, int count);
int main()
{
double sbuf[MAX];
double rbuf[MAX];
int i;
for (i = 0; i < MAX; i++)
sbuf[i] = (i + 1) * 1.0;
chamaleon (sbuf, rbuf, MAX);
for (i = 0; i < MAX; ++i)
fprintf(stdout, "rbuf[%i]->%f\n", i, rbuf[i]); …
My code has main function one time.
I don't know sometimes C make me nervous.
If that's the case your {} error may have thrown off the code parser and as a result generated the _start error...Its working now right?
Unfortunately I can't write here all the code from project.
Do you believe that I have forgot a '{' '}' character ?
That shouldn't generate the error you have...The error could be two things, it could be that the compiler can't find main or that it's finding two mains or _start places in your code.
An example
test.c
#include <stdio.h>
void myfunc(void)
{
fputs("Hello, World!\n", stdout);
}
If I try and compile this code like so
gcc test.c -o test
It'll produce the error you had because its trying to create an executable but can't find the _start function main.
Are you sure you should be compiling to an object file say test.o
gcc -c test.c
Its an error because you can't dereference a void pointer..rbuf is a void pointer.
*rbuf= &svar;
What exactly are you trying to a accomplish here? What is the purpose of the program?
Sounds like your code doesn't have a main function...Could you post the code and the compile line.
std::cerr is an I/O channel that can be used for errors...Its almost the same as std::cout except its not buffered.
Why two asterisks? Its a pointer to a pointer...so two asterisks.
What's this line?
farray = new float*[rows * sizeof(float*)];
That is how you allocate the memory for three float pointers.
This one?
farray = new float[cols * sizeof(float)];
Here I'm allocating the arrays of floats for each of the three pointers.
and I do use ifstream.
I tried your problem but used pointers to pointers for the array...
testfile
3 6
3.9 4.5 2.1 1.0 2.4 4.3
3.1 4.2 5.1 6.2 1.0 2.7
1.2 2.3 3.1 4.2 5.2 6.4
testit.cpp
#include <iostream>
#include <fstream>
int main()
{
int rows = 0;
int cols = 0;
int count = 0;
int row_count = 0;
float **farray = (float**)NULL;
std::ifstream fin("testfile");
if (fin.fail())
{
std::cerr << "Could not open file" << std::endl;
return 1;
}
fin >> rows >> cols;
farray = new float*[rows * sizeof(float*)];
for (int i = 0; i < rows; ++i)
farray[i] = new float[cols * sizeof(float)];
float value = 0.0;
while (fin >> value)
{
farray[row_count][count++] = value;
if (count >= cols)
{
count = 0;
++row_count;
}
}
fin.close();
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
std::cout << farray[i][j] << " ";
}
std::endl(std::cout);
}
return 0;
}
The code is pretty rough but you can clean it up and see if it works for you..
I think you'll find this a better way to read a file of floats..
testfile
3.9 4.5 2.1 1.0 2.4 4.3
3.1 4.2 5.1 6.2 1.0 2.7
1.2 2.3 3.1 4.2 5.2 6.4
testit.cpp
#include <iostream>
#include <fstream>
int main()
{
std::ifstream fin("testfile");
if (fin.fail())
{
std::cerr << "Could not open file" << std::endl;
return 1;
}
float value = 0.0;
while (fin >> value)
{
std::cout << value << std::endl;
}
fin.close();
return 0;
}
Shouldn't this
3 5
3.9 4.5 2.1 1.0 2.4 4.3
3.1 4.2 5.1 6.2 1.0 2.7
1.2 2.3 3.1 4.2 5.2 6.4
be
3 6
3.9 4.5 2.1 1.0 2.4 4.3
3.1 4.2 5.1 6.2 1.0 2.7
1.2 2.3 3.1 4.2 5.2 6.4
Thanks for link. But I don't understand how using a select instead of accept can help me to finish using socket when I send a signal to do so.
Could you explain this in more detail..."can help me to finish using socket when I send a signal to do so". The listening socket?
Here's an example of using select() which can solve your problem
So I'll just call fork again in the parent block?
Yep that's right..The parent calls fork and the child calls execvp.
That's because your calling execvp in both the parent and the child...Only call execvp in the child.
Calling fork creates a new process...Calling fork again will create another process and calling it again will create another...Just make sure you know who's calling fork...I would delegate that to the original process.
To answer your second question...You could use the system() function
int system(const char *command);
DESCRIPTION
system() executes a command specified in command by calling /bin/sh -c
command, and returns after the command has been completed. During exe‐
cution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT
will be ignored.
Any exec function replaces the calling image with its own..So that would explain why the calling process closes...
If I was doing this, I would use the fork/exec combination.
You have major problems in your code...I tried compiling it and set off many errors and warnings...Try starting with this shell.
#include <iostream>
#include <cstring>
class string
{
public:
string():s(NULL), itssize(0) {}
string(const char* const cstring);
void displayit() const { std::cout << s << std::endl; }
private:
char *s;
int itssize;
};
string::string(const char* const cstring)
:itssize(strlen(cstring))
{
s = new char[itssize + 1];
for (int i = 0; i < itssize; ++i)
s[i] = cstring[i];
s[itssize] = '\0';
}
int main()
{
string me("my string");
me.displayit();
return 0;
}
O.K. What do you have so far?
Try this one
MyMatrix: MyMatrix.o MyStringMain
gcc MyMatrix.o -o MyMatrix
MyMatrix.o: MyMatrix.c
gcc -c MyMatrix.c
MyStringMain: MyString.o MyStringMain.o
gcc MyString.o MyStringMain.o -o MyString -o MyStringRun
MyStringMain.o: MyStringMain.c MyString.c MyString.h
gcc -c MyStringMain.c
MyString.o: MyString.c MyString.h
gcc -c MyString.c
.PHONY:clean
clean:
rm -f *.o test.out
Why would you be searching for an address in a range? You already know the address right? Are you searching for a value that may be stored in a range of addresses?
Your function call with
char * maxStr = maxn(str, 5);
Does it make sense to have
str.size();
since str is a c-string?
Whoops. I knew that. But now it won't stop outputting a.m.
D:
Your function
void convertTo12(int& hour)
only changes the am pm character locally. You need to pass the character as a reference.