C :: File Which Can Be Compiled In Linux Via GCC
Aug 16, 2013I have a c file which can be compiled in Linux via GCC , but when I compile it in NetBeans via Cygwin or MinGW , it doesn't work and keeps throwing a segmentation fault.
View 14 RepliesI have a c file which can be compiled in Linux via GCC , but when I compile it in NetBeans via Cygwin or MinGW , it doesn't work and keeps throwing a segmentation fault.
View 14 RepliesToday I am given an assignment to find the zeroes of a function using Newton-Raphson method. Till now, the input I gave to a program was data. But now the function (whose zeroes are to be calculated) is also an input.
Is there a way where I can compile and build a function into a file and during execution of my program open the file and run the machine-language code in it and get the return value?
My socket.cpp program got error. it showed "socket.h: no such file or directory". I had put my header file (socket.h) in the same place with my source file.
View 1 Replies View RelatedI am working on a script compiler that must output compiled script into binary file. Compiling etc is not a problem. The problem is detecting some specific cases. Nothing seems to work. If it works, then it breaks as soon as i modify the script.
Here is example "script1":
Code:
1VAR1 c1 = 44
2VAR2 c2 = 66
3beginscript
4if(c1=44)
5do_nothing
[Code] ....
Second example "script2", when there can be also some command between ENDIF and ENDIF. In this case: do_nothing command.
Code:
1VAR1 c1 = 44
2VAR2 c2 = 66
3beginscript
4if(c1=44)
5do_nothing
[Code] ....
The INDEXES before each line are not in actual script. They are just to point YOU to specific lines. Although the INDEXes are in compiled script!! This is very important. As you see there can be simple IF_ENDIF and nested (more complex) IF_ENDIF.
i.e IF_ENDIF inside another IF_ENDIF.
There are also IF_ELSE_ENDIF and some other ones, but im trying to make simple IF_ENDIF work first.
ENDIF is "SPECIAL" command, the IF, DO_NOTHING are "usual" commands.
"Usual" commands must always jump over(!) the ENDIF. ALWAYS!!
They must "ignore" them!
One strong RULE is like this for usual commands: always jump over any ENDIF, not matter what. If there is one, two or more ENDIF's in a row, then just jump over them to the closest NEXT usual block command. If there is some "usual" block command between multiple ENDIFs, then jump to this command and this command must therefore check whats next command right after it. And do the same: check if next command is ENDIF, if yes, jump over it, until "usual" block command is found.
This is the place im stuck. When i some time ago thinked about some ideas, i saw some patterns. One of them was that: Seems like if its nested IF_ENDIF, then every usual block command jumps out of it, i.e. right after the final ENDIF of this current nested IF_ENDIF.
But as soon as i added do_nothing between the two ENDIFs the so called "pattern" broke. In script2 above you see index 11 is do_nothing. Ok its in nested IF_ENDIF it should jump out to command index 17. But no, because there is do_nothing between index 13 and 16. If we jump out at index 11, the command 14 would never execute. This is a BIG NO. One idea i was thinking and trying was to use STL::FIND, STL::FIND_IF to find next "usual" command after specific index. But my code seems to crash sometimes and not work always.
Code:
bool NextNonENDIF(int i) {
return (i!=98);
}
int findNextBlockCmd(vector<int>&vec, int curidx)
[Code] ....
Here i pass him the vector that contains all the command TYPES in current script. Each command has its own TYPE or better called unique ID in which way compiler knows what is what. So in this case im trying to find a command thats NOT "ENDIF", in other words im trying to find next usual command after specific type of command. Lets just say the TYPE or unique ID of do_nothing is 555, im trying to find it.
How i should continue with this? What to use maybe stl::stack, some custom command indexing, some sort of labelling for usual commands in nested IF_ENDIFs or what?
In general, look script2, and i ask: There is index 11, this guy should look if there is any usual block command left for him before the final ENDIF at index 16. If there is, jump to it. If there is none, jump out of this nested IF_ENDIF to index 17.
Question: how to do it? What algorithms to use? I can use STL, BOOST, whatever. And i can use C++11.
I have code that creates an index file created from a data file of records.
#include <iostream>
#include <fstream>
#include <map>
#include <sstream>
#include <string>
#include <iomanip>
using namespace std;
class Record {
[Code]...
I now need to write a second program that allows the user to enter a command on the Linux command line such as
search 12382 prog5.idx
and returns the information for the record with that key. The code I included for the index file is correct and works properly, but how to write the second program.
Here is the index file created by the first program:
8: blank 0 $ 0.00
12165: Item16 30 $ 7.69
12345: Item06 45 $ 14.20
12382: Item09 62 $ 41.37
12434: Item04 21 $ 17.30
16541: Item12 21 $ 9.99
21212: Itme31 19 $ 8.35
34186: Item25 18 $ 17.75
41742: Item14 55 $ 12.36
The top line is a dummy record, the first number is the size of the file.
I am using visual studio 2012 on windows 7. but, when I have compiled my programs and run them on an older pc to test out its functions, I receive an error saying that the program is not a "valid win32 application." I have even tested this with a very simple hello world console application, but the problem still remains. Where is the error coming from? is the application corrupted during transport? (upload to internet) or are programs compiled on win 7 incompatible with win xp
View 6 Replies View RelatedI have a weird problem, my computer restarts imidiately after program writen in dev-cpp is compiled AND run. When I run any program, it lasts about 1 second, then program closes, and computer reboots. It doesn't matter whether program is writen now or earlier, my dev-cpp version is 4.9.9.2. Source code can be as simple as this:
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
getch();
return 0;
}
and it restarts anyway...
(C++ question) I need to be able make a compiled code (like a .dll?) which other programmers can use on linux, win,, mac, etc.
The compiled code would simply do calculations and spit out an answer in memory.
I need it to have certain functions that they can easily call and understand (without actually seeing the source).
I am looking at reducing the size of a compiled executable for easier distribution.
What factors affect the size of an output executable?
Would literally having defined and implemented less functions, would make the exec. smaller? Meaning that instead of have a DLL ( yes im on windows ), I would download the source code of a library and comment out the functions ( and code ) that I am not using -- Would this process decrease the size of my exec.?
I have a C++ code that reads the database password from the registry and decrypts it using CryptUnprotectData. We have to deploy this application on a Windows 7 machine.
When I compile my code on Windows XP and run it on the test Windows 7 machine, it works absolutely fine. When I compile the same code on my laptop having Windows 7 and run it on the test Windows 7 machine, CryptUnprotectData fails with GetLastError() return '87'. If I run this application on my own laptop with Windows 7 on it, it again works fine probably because my laptop has a lot of things installed including Visual Studio and all the service packs etc.
I believe I have missed out installing some dependency on the test Windows 7 machine but I am unable to figure out what is that. What is it that's making the Windows XP compiled code running fine on the test machine and not the code that's compiled on Windows 7.
Here is the call to CryptUnprotectData in the code:
if (CryptUnprotectData(
&cipherText,
NULL,
NULL, // Optional entropy
NULL, // Reserved
NULL, // Optional PromptStruct
CRYPTPROTECT_UI_FORBIDDEN,
&plainText))
[code]....
I'm attempting to write a little UDP socket library in c++ on linux so a user can just create a new instance of a UDPSocket class, specify destination ip and port, and just connect. Then the user should be able to call send() or receive() in any order they want.. and here I encounter a little problem..
Most of the tutorials for udp socket sending out there include a bind() call when you create your "server" that is supposed to receive data, but the code that send data does not need one. Because I also want my library to support unicast/broadcast/multicast, I have read that I need to set the socket option SO_REUSEADDR on my sockets (since multiple sockets will need to be connected to same destination IP/port for broadcast/multicast)
My question is.. do I need to create 2 socket handles per "UDPSocke in order to make this work? One for sending and one for receiving data? In my code when I try to work with only 1 socket, it is only able to receive stuff from itself on unicast.. Or should I just remove the SO_REUSEADDR when in unicast mode, then try to bind with both sockets, accept that the bind will only work on the 1st socket, and take it from there?
I have a code that I'd like to debugg it.
Question
1 - What is the correct command line to use the debugger ?
2 - Do I need to install additional software for the debugger ?
if yes what it's name?
I use ububtu 12.4compiling command: gcc abc.c -lpthread -o abc
This is what so far i did
Code:
#include <stdio.h>#include <string.h>
#include <ctype.h>
#include <bsd/string.h>
int
main(void)
[Code] ....
How to do this Using the fork(), execvp() and waitpid() system calls, launches the requested program and waits until the program has finished.
I am an experience C programmer but never implement GUI.
I need to make a demo implementation that will be run on Linux and will implement GUI.
I searched the WEB and found lot of information, among is implementing the GUI in HTML and run the API through web browser.
How can I make such implementation in C?
I want to use two separate files in 1 program, but cannot get it to work. I don't know if it's my files or the compiling thats wrong. I have never used 2 files in my programs so far. Only used #include <stdio.h>.
Here are my files:
extern_static.c Code: extern int i;
int main(void)
{
[Code]....
I have this following piece of code:
int id = 5;
const char *ptrId;
ptrId = ( int_to_str(id) ).getPtr(); // Works in Solaris well
But the above code prints some junk values when I run the same on Linux machine. But the following works well on Linux:
String temp = int_to_str(id);
ptrId = temp.getPtr();
The prototype of getPtr() is:
const char* String::getPtr() const
I want to create command line game in Linux but I don't know to get the key state. I heard of getch() but that stops the program.
View 1 Replies View RelatedI want to open an application A from another application B. By opening it, I don't want to open it within B. I found many ways to call an application from within another. However, what I want to do is open the other one(A) simultaneously. How can I achieve this? fork() and exec() seem to open A within B. I am developing a code for Linux and Mac.
View 7 Replies View RelatedWhy is using namespace needed in linux but not in turbo c++?
View 1 Replies View RelatedI have implemented MD5 checksum algorithm by using C language, but it is resulting correct value in windows but not in Linux?
// Constants are the integer part of the sines of integers (in radians) * 2^32.
const uint32_t k[64] = {
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee ,
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501 ,
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be ,
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821 ,
[Code] .....
I'm trying to implement this on ubuntu, to compile and run only under ubuntu.
I found 100s of other attempts at answering the general question of arrow key press in c++. Nothing solid.
Some recommend using the Readline for the functionality I am trying to implement, but I need to stay clear of GNU licences if I can for this project. And some tips only work on projects for windows machines... for example the conio library.
For linux there may be the option of using the ncurses library which I will take a look at, but I am stubborn and want to implement this myself. It should be an easy straight forward thing to do, which is why I am a bit frustrated at the moment.
Here is my test code so far.
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
using namespace std;
int main(void) {
char a;
stringstream ss;
string s;
[Code] ....
So! This works... 80% of the problem is solved. If you compile this, g++ under linux, ubuntu in my case, and run. Each keystroke reveals the correct key numbers.
q=113
w=119
when I click on the up key I get,
up = 279165
I thought, I can use this number is a if(int == '279165') to detect the up key.
I was not so lucky... this int is not behaving like an int!
So I modified the code to see it I could carry out an int operation on this number.
I added a 100000 to int i.
cout<< i + 100000;
Code:
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
using namespace std;
int main(void) {
char a;
stringstream ss;
string s;
[Code] .....
Compiling and running this, and pressing the UP key gives the following number.
100027100091100065
Some some sort of array, something like, [27][91][65].
I tried all ways to access these individual numbers, actually the third one for comparison purposes, but no luck.
For completeness sake I list the other arrows.
UP = [27][91][65]
DOWN = [27][91][66]
LEFT = [27][91][68]
RIGHT = [27][91][67]
A little further digging shows that these numbers are derived from the representation of a "multi-char" constant, the data type given when pressing special characters...
Now here is the main problem I have, I can find ANY decent documentation on how to handle and play with "multi-char" .
I'm trying to build a Linux Process Scheduler from scratch but dont know where to start.
View 1 Replies View RelatedI'm new in IPC. I would like to implement a signal of a new message, which calls the slot function, eg .:
Code:
msg_on_newMessange(type, &slotFunction);
My code:
Header file: messages.h
Parent file: parent.c
Child file: child.c
How can I do this ?
I want to create a program that lets you download torrents on linux ... how to start ...
View 1 Replies View RelatedI am trying to detect keys pressed on a keyboard and mouse on both, Windows and Linux but I am unsure what would be the best practice way to do so. Will I have to detect the keys for each platform individually? Would you make use of an event listener? What's the best way to detect the input-devices?
View 1 Replies View Relatedis there a way to create a keylogger for windows and Linux using the same function. Any function to do it on linux and how to use it.
View 3 Replies View Related