c

Find the rightmost occurence of a character in C?

Hey all, I'm trying to find the numeric position of a character or number of characters in a string. I'm able to figure out how to see where character "a" is in the string "abcd" but if I put "abcda" it only prints out 0, meaning that it counts only the first instance. I want to find the last or rightmost occurence of this string. Her...

Can you define the size of an array at runtime in C

New to C, thanks a lot for help. Is it possible to define an array in C without either specifying its size or initializing it. For example, can I prompt a user to enter numbers and store them in an int array ? I won't know how many numbers they will enter beforehand. The only way I can think of now is to define a max size, which is n...

Bind: Address Already in Use

I'm trying to run my server program but I keep getting this error: ERROR on binding: Address already in use int main(int argc, char *argv[]){ if (argc < 6){ printf("usage: stringSearcher <filename> <stringLength> <searchLength> <nChildren> <nThreads> <blockSize>\n"); exit(0); } char* fil...

Call assembly in buffer in C

Is this possible? I want to place intel assembly code into a char buffer, and then execute that code from within a C program If I placed the assembly code into a buffer, could I cast it into a function pointer and call that? I am using GCC and linux ...

Debugging a Static Library with the Eclipse CDT

I'm working on getting set with Eclipse CDT for some embedded development and I'm having difficulty getting source level debugging working for static libraries. I'm using my own Makefiles, so that is my first suspect right now, especially since gdb claims that no symbol table info is available for the functions with no source. When usi...

Does malloc allocate memory from 0 to positive infinity?

I wrote a test program thinking that the address of p1 will be less than p2, but when I compiled the code, the address of p2 turned out to be lower (p1 is 8 units larger than p2). I also heard rumors that 2 adjacent memory blocks will combine themselves automatically. Does that play any part in the following code? void main(){ char...

Matching words from a dictionary(an external txt file) with an article (another external txt file)

I've managed to store the article into heap, but what should I do with the dictionary? I tried using strcpy(tempArticle[i], dictionary); but it didn't seem to work? would someone give me a hint as to what to do in the next step? #include <stdio.h> #include <stdlib.h> #include <string.h> void spellCheck(char article[], char dictionar...

Difference between byte and char in C

I am wondering why I can't compile an example from book. I simplify the example here to avoid posting example from a copyrighted book. #include <stdio.h> BYTE *data = "data"; int main() { printf("%s", data); return 0; } When compile with g++, i get error, error: invalid conversion from 'const char*' to 'BYTE*' The progr...

Valgrind: Deliberately cause segfault

This is a mad-hack, but I am trying to deliberately cause a segfault at a particular point in execution, so valgrind will give me a stack trace. If there is a better way to do this please tell me, but I would still be curious to know how to deliberaly cause a segfault, and why my attempt didn't work. This is my failed attempt: long* p...

load libavcodec in Qt-Projekt

Hi. I want to include the libavcodec in my Qt-project. Should I do that with #include <ffmpeg/libavcodec.h> or with something more Qt, for example QLibrary mylib("libavcodec"); And also a question to understand if I really got it: To use libavcodec, do I need to import the source-files or the .dll? ...

Can I and should I use CMake for my setup

The projects I work on are organised into root folders (VOBS) as follows: |--BUILD_FOLDER | |-- BUILD_SCRIPTS | |-- SOME_MORE_CODE | |--COMPONENT_A |--COMPONENT_B Because they are ClearCase VOBS there is no higher level root folder to place a CMakeLists.txt This setup doesn't seem to fit the CMake pattern... Is this a show-stopper t...

How to manipulate an image at pixel level in C?

How do I read an image in C so that I can have direct control over its pixels (like we do in MATLAB)? I tried the old way: FILE *fp; fp = fopen("C:\\a.tif","r"); that just gives me the ascii form of the image file (I think). How can I get pixel level control over the image and do some basic operations like say, inverting the image? ...

How to check if stdin is still opened without blocking?

I need my program written in pure C to stop execution when stdin is closed. There is indefinite work done in program main cycle, and there is no way I can use blocking checks (like getc()) there (no data is supposed to arrive on stdin - it just stays opened for unknown time). I intend to use described functionality in realization of ne...

Cocoa - Add Video Watermark General Info

Just looking for how to programmatically add a watermark or some sort of overlay to video using cocoa. Not looking for a step by step ( although that would awesome ), but more or less looking for where I should start looking to learn how. Are there frameworks developed to work for this. Would like something native to cocoa or objectiv...

C format specifier question

While I was working i came across a code which was written by somebody else. i see a statement as , sprintf(o_params->o_file_name, "%s_%s_%04.4d_%s_%s.ASC", "OUTD", "RM", sequence_no, DateStamp_buf1, TimeStamp_buf1 ); In the above statement, I see %04.4d. Is this a correct format specifier? The variable sequence_no ...

How to make a C code to fetch some content from the internet?

Suppose I want my C code to fetch the headline from a website, like www.example.com How to do that? Can I write a program in C to do this? give me a start... ...

Convert float array image to a format usable for opencv

Hi, i wonder if there is a easy way to convert my float array image to iplimage, which can be handled by opencv. Of course i could create an empty iplimage with the same size and just copy ever pixel from my float array image to the emplty iplimage, but is there more elegant solution to this. Maybe a faster less memory consuming method,...

Which language to use for implementing few Linux shell commands (homework) - plain C or C++?

I need to implement a few commands of Linux shell for my homework - 5 or 6 of them, including ls. Do not know much about which parameters to implement for each of commands... I planned to use C++, but when I asked my colleague for advice what language to choose - plain C or C++, he said that interpreter was not a program in traditional ...

What is a good book/guide for socket programming in C?

Could anybody please tell me which is best guide/book/material for socket programming in C? I am reading beej's guide for network programming but it just gives an overview. Can you suggest any other books or guides? ...

syncing iostream with stdio

I am trying to add iostream to the legacy code and thus want to sync those two libraries. According to this article, I should use std::ios_base::sync_with_stdio. Now, I wonder how it is used in practice (examples please), side-effects I should be aware of. Thx ...