know of a handy function (or library) for converting between different text formats? I've heard of a library called iconv but I've no familiarity with it. However, it looks promising (from what little I can find out about it...)
Specifically, the text %20 is often used in hypertext to indicate a space character - so the string "Hello There" would get changed into "Hello%20There". How can I easily change between one and the other?
Obviously I could use string replacement functions but that'd need me to anticipate every potential hypertext code sequence.
whats the difference between functions as pointer and normal function, eg:
void function1(void) void *function1(void)
What is the difference between the two?I'm doing parallel programming and we use pointer functions (void *function1(void)) when calling threads. I want to why it is done.
I have been trying to find a way around the following:
I am using a library functor to solve the root of a non linear equation. It passes two doubles and the name of a function that contains the equation to be solved.
I want to create a C library function that i can directly call in my code from any .c file having main program.following are codes...code of library function "foo.c"
Code:
#include "foo.h" int foo(int x) /* Function definition */ { return x + 5; } header file "foo.h"
Code:
#ifndef FOO_H_ /* Include guard */ #define FOO_H_ int foo(int x); /* An example function declaration */ }
[code]....
to use this i have to compile the file in below manner...
Code: gcc -o my_app main.c foo.c
My concern here is that i want to compile the main.c and use function without compiling foo.c with i.e.
Code: gcc -o my_app main.c
any user of this function should only compile his program and should be able to use the function, the foo.c file should remain hidden from him
my system is Linux 2.6.18-308.4.1.el5 #1 SMP Wed Mar 28 01:54:56 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
I am working on a problem that requires a nest for loop to be converted to a recursive function. I am going to provide just the code instead of the entire program.
Code:
for (R1=1; R1 <+3, R1++){ //for loop printf (something); } // the recursive function void loopR1 (int R1, int max){ if (R1 <= max){ printf (something);
[Code]...
when calling the recursive function in main i am using the following statement...
I have int pointer called p and i want to calculate average.Since average involves using double or float so i am trying to convert this in the function averagetemp. It still gives me an error saying "cannot be converted"...
#include <iostream> using namespace std; int* createArray(int n); int lowesttemp(int *p,int f); int highesttemp(int *p,int f); double averagetemp(int *k,double f); void print(int *p,int lowest_temp,int highesttemp,int average_temp);
Code: class VAR_EXPORT VAR { public: }; VAR_EXPORT QDataStream &operator>>(QDataStream &p_stream, QSharedPointer<Data>& p_data)
[Code] ....
Above compile and build ok. But when i build another library that use the above, i was shown with all errors complaining operator << and >> definition of dllimport function not allowed
error C2491: 'operator >>' : definition of dllimport function not allowed error C2491: 'operator <<' : definition of dllimport function not allowed
error expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|. error expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|. error expected '{' at end of input|.
#include <iostream> double fact (int f); //declaration of factorial function double power(double x, int y); //declaration of power function double sin(int x); //declaration of sine function //double cos(int x); //declaration of cosine function //double tan(int x); //declaration of tangent function
I have a class "Result" with a single template function Set(const std::string& arName, T& val) and a specialization of this function Set<Real>(const std::string& arName, Real& val) where Real is a typedef for double. The class is in a shared library and I use it in my main program. If I do result->Set<GLOBAL::Real>("U", 100.0); the wrong template function is called!
I check this by the output with std::cout.
Maybe it's a problem with the typedef.
If I link the object file of the Result class directly to my main program (no shared library), it works.
I have been asked to develop a program with 6 methods which I have presented below. The aim of the program is to find and generate a magic square with a given dimension. This is a console program and so the 'Main' is also provided. However, I am having a problem with my code. When ever I try to generate a magic square it continuously cycles through 'forever' and I have never yet got a magic square; no matter what dimension I enter.
I must use methods 'CreateRandomlyAssignedArray' and 'CheckSquareMatrix'. There is another method 'SearchForValue', which we were told to creat. How this can be useful.
I have provided my code below:
class Program { static Random rand = new Random(); static void Main(string[] args) { int[,] array = new int[5,5]; array = GenerateMagicSquare(5);
Write a function that generates 1000 normally distributed (Gaussian Probability Distribution) random numbers. Range should be between -3 and +3. Numbers should be double floating point.
There's more to it than that, but I've got it from there.
An object of this class will return a normal random when it's member function operator()() is called:
template<typename RG> double class NRG::operator()() { static int flag = 0; static double N2 = 0.0; if(flag==0)
[Code] ....
However, when I run this I get an error which says:
C:UsersavadhootDesktopb.cpp|69|error: 'template<class RG> class NRG' used without template parameters| C:UsersavadhootDesktopb.cpp|69|error: expected identifier before 'operator'| C:UsersavadhootDesktopb.cpp|69|error: two or more data types in declaration of 'operator()'| ||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
The following function finds the normal to a terrain represented by a texture. I found it somewhere online , it works but i couldn't understand the math behind it. So , How (or Why ?) does it works ?
//psuedo code Vector2 normal(x,y) { Vector2 avg; for(int w = -3; w <= 3; w++) { for(int h = -3; h <= 3; h++)
I've been reading about libraries; How to make them, how to use them, the different types of libraries, etc..
When using a shared library, does the program require that library to be installed on the computer after the program has been compiled into an .exe?
Ie.. if somebody downloaded a "Helloworld.exe" that I had compiled on my computer using a shared library (that wasn't part of a standard operating system), would they also need that shared library on their computer for the program to run without errors?
and for Static Libraries, when I compile a program using a static library, does it include in the final binary only the functions of the library that are actually used, or does the compiler add in the entire library?
I wrote the following program shown below that produces a normally distributed random number several times, and then takes the average of them. The problem that I have been having though is that the output it has been producing is 0.0288385 despite the fact that I set the mean of the normal distribution to be 0.1. Why this output value would be so far off from 0.1 despite having averaged over such a large number of random numbers namely 10,000 of them? Also, how to randomly seed this random number generator such that it gives a different value each time its run perhaps by seeding it with the windows timer? Below is the program.
#include <iostream> #include <random> using namespace std; int main() { default_random_engine generator; normal_distribution<double> distribution1(0.1,3.0); double number1,sum,n;
I'm implementing an normal_distribution to select objects on a vector. The thing is I can't use values greater then 1 or less then -1. Here is what could be done:
The question is if the distribution would loose it's power to be a normal distribution, because some of the gerated numbers wouldn't be used. Any way to set ranges for the distribution?