C

22K

Solutions

13K

Contributors

C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, so it has found lasting use in applications that had formerly been coded in assembly language, including operating systems as well as various application software for computers ranging from supercomputers to embedded systems. It is distinct from C++ (which has its roots in C) and C#, and many later languages have borrowed directly or indirectly from C.

Share tech news, updates, or what's on your mind.

Sign up to Post

Please explain Gamma Compression algorithms. How to write Gamma Compression algorithms for typical video and image processing system?  Please provide some detailed examples.  How to gain sufficient understanding to be able to write Gamma Compression in 'C' or MATLAB?
0
Announcing the Winners!
LVL 13
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

Using Windows Forms

I have a tabcontrol , each page has a datagridview.  I know the  tab page name

tabData.SelectedTab.Name

let's say I have tabPage1  the datagridview on that tab is dgvPage1.   Now I want to get the selected row

int row = dgvPage1.CurrentCell.RowIndex;  


How can I do this if all I know about is the grid I want is   -- String  VariableName  =  "dgvPage1"  stored in a variable.

int row = (VariableName).CurrentCell.RowIndex;  
String Person = (VariableName).Rows[row].Cells[0].Value.ToString();
0
I found this code in the Open Source code for Wireshark, and it appears it is returning a local variable, which I thought was not allowed, since the variable goes out of scope once the routine returns.

However, since it's a static routine, maybe that makes it OK,

Is it OK to return a local variable from a static function?

static GSList* local_interfaces_to_list_win(void)
{
	GSList *interfaces = NULL;
...
	return interfaces;
}

Open in new window

(This is C code.)
1
Hello

How can i pass an argument to a visual studio .exe (C++ project) from the command line i.e. cygwin?

Please note that I do not want to pass the argument via the Visual Studio GUI under debugger->Command Arguments.

So I would like something like this:
cygwin>a.exe 4

thanks
0
Hi all,

  I do want to store  "directory path" as a  key and corresponding value as a value. The key would be 1024.

  If I take std::map, I guess it would be performance hit with huge number of entries.

  It has to maintain this ds inside kernel module. What is the best ds to implement this in C++ 11?

Thanks,
Bvm.
0
With Lilypad e-textiles do you have to pair an Arduino board (nano or uno) with it or are these programmable themselves with Arduino software.  I have multiple LilyPad Arduino Simple Snaps and would like to program them to allow a student to push a button and have led lights go off in succession.
We are attempting to make interactive maps like what you would see in a museum.  Button goes off and the lights light up an army path or the outline of a state.
0
Hi,

I want to put a project I am writing on GitHub for public viewiewing.
What I want to make sure is no private information is in there.
I know my code does not have any references in there.

So things I am concerned about are.

My microsoft account email address
My azure devops Repos path - e.g. https://dev.azure.com/Code/Project/_git/xxxx etc
+ anything else I am not aware of.

I am assuming I would need to remove a git subdirectory somewhere.

Anything else - any other hidden files etc?

My original code is in Azure Devop's at the moment.
I am happy and prefer if I can not to have all the history there.

Which is why I was thinking of manually uploading it all.

Any thoughts / ideas.

Thanks,

Ward
0
I have a problem running any c programming using Widnows 10 command prompt, gcc ver is 3.4.2
please help
gcc: Internal error: Aborted (program collect2)  
Please submit a full bug report.
See <URL:http://www.mingw.org/bugs.shtml> for instructions.
0
Dear all,

Using Turbo Pascal or C or Turbo C (well primitive), how I read several columns with numbers from a text file and give the sum of each one?

Thank you in advance (if I found anyone that have programmed in Pascal.
0
IOS project using swift
On my story board I have a launch screen that is the entry point. Now I want another view controller, I drag a view controller onto the storyboard. I create a cocoa touch class that is a subclass of UIViewController, naming it DTViewController. On storyboard, I select my new view using the left most icon on the top of the view and go to custom class. I select DTViewController as my custom class.  To stop warnings about my view being unreachable I check "Use StoryboardID" and enter MyDeskTop as the Storyboard ID. I drag a label onto the new view.

I have the following code in AppController.swift
private func handleAppState(){
if let user = Aut.auth().currentUser{
let vc = DTViewController()
rootViewController = NavigationController(vc)
} else {
rootViewController = LoginViewController()
}
}

Open in new window


When I run the app the splash screen appears and then the DTViewController appears. The problem is it's not picking up on the View in the Storyboard, just the DTViewController class. My evidence is the label doesn't show up but if I change the background color in code in DTViewController the change shows.

What am I doing wrong?
Thanks!
0
Ensure Business Longevity with As-A-Service
Ensure Business Longevity with As-A-Service

Using the as-a-service approach for your business model allows you to grow your revenue stream with new practice areas, without forcing you to part ways with existing clients just because they don’t fit the mold of your new service offerings.

Error messageHello Everyone,
I hope you all are doing well.  Attached, I have a Visual C ++ error message that a user got when he was at a work training.  He claims that other people were able to use it just fine.  I am waiting to hear back to see if there is anything different with their computers as compared to his.  The program is contained in a folder with a bunch of system files that application calls upon, it is not installed on the computer itself.  I and another tech got a copy of this folder and we get the same error message.  We are going to play around with it and see if we can make this work somehow.  I am just wondering if anyone knows about this.  
The user's computer is running Windows 7 pro
My computer is running Server 2016 Datacenter
my co-worker's computer is running Windows 10 pro

 If you guys think it an issue with the software itself, please let me know.  Any kind of programing fixes that people give me, I will not understand as I am not a software developer and if the fix comes down to that I will simply say that the developers need to fix this.

Thank you guys!!!
0
ANSI c on OSX 10.13.6 <br>
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix

I'm learning `c`

This is a function that manually (character-by-character) adds two character strings representing large numbers (that exceed the unsigned long long or double size).

It functions fine with any two strings 14 or less characters long, but segmentation fault 11 with any strings greater than 14 chars.

Changing the string's memory allocation method seems to have no effect (I.e. from
char[15] addend1; // not a ptr

Open in new window

to
char *addend1 = (char *) malloc(sizeof(char) * (16) ); // pointer

Open in new window


One things that's curious, is that it seems to segfault on the ...
for (int j = maxlength - 1 ; j >= 0; j--)

Open in new window

... prior to accessing either of `addend1` or `addend2`, but I'm not able to find an error there or change it to prevent the segfault.  

Am I misreading where the error arises, or could it be related to the for loop?

MAIN.c

	#include <stdio.h>
	#include <stdlib.h>
	#include "../../c-library/include/addViaStrings.h"
	
	int main(void) {
		//	s[0] = 72; s[1] = 101; s[2] = 108; s[3] = 108; s[4] = 111; s[5] = 32; s[6] = 87; s[7] = 111; s[8] = 114; s[9] = 108; s[10] = 100; s[11] = 0;
	
		// WORKS
		// char s1[] = "14073748835532";
		// char s2[] = "14073748835532";
	
		// FAILS
		char s1[] = "140737488355328";
		char s2[] = "140737488355328";
	
		char *sum = addNumericStrings(&s1, &s2);
		printf("main.sum = %s\n", sum);
	}

Open in new window


addViaStrings.h


Open in new window

0
Hi I have a 2D vector in a library which gets populated with different types of data this part is working fine now I need to pass the 2D vector back to my main app from a function call but this function call is failing

Here is the structure that makes up the vector in the library and how I am trying to call the data in the vector from a function:
//Library code
typedef struct _DEVICEDETAILS
{
	std::string IPaddr;
	int HTTPPort;
	int HTTPSPort;
	int RTPSPort;
	std::string Model;
	std::string Name;
	std::string token;
	std::vector<std::string> RSTPURL;
	std::vector<char*> data;
	std::vector<size_t> datalen;
	std::string _mediaXaddr;
	int Encoding;
	int Width;
	int Height;
	int Quality;
	int FrameRateLimit;
	int EncodingInterval;
	int Bitrate;

}DEVICEDETAILS;

struct ONVIFDEVICE
{
	std::string MacAddr;
	std::vector<DEVICEDETAILS> _videotype;
};

ONVIFDEVICE m_MacAddr;
std::vector<std::vector<ONVIFDEVICE>> v_Device;

void GetOvifInfo(std::vector<std::vector<ONVIFDEVICE>> &returnInfo)
{
  other code .......
   int m_size =v_Device.size();
   v_Device.resize(m_size+1);
   v_Device[nFindDev].push_back(m_Mac); // info gets populated into each element here
   nFindDev++;
   
  //Need to do a deep copy from vector v_Device to  vector returnInfo

}

// Main App code
typedef struct _mDEVICEDETAILS
{
	std::string IPaddr;
	int HTTPPort;
	int HTTPSPort;
	int RTPSPort;
	std::string Model;
	std::string Name;
	std::string token;
	std::vector<std::string> RSTPURL;
	std::vector<char*>

Open in new window

0
I have a Dell 5810 workstation with Win 10. Drive c: = 1tb ssd. Drive d: = 1tb ssd. I have slots for two mechanical drives. One has failed and instead of replacing it with one 6 tb drive I was wondering if I purchased two 4tb WD black drives and used them in a raid 1 configuration that it would be my best solution. I do not need speed on the two mechanical drives. They would essentially be shown as a single 4tb drive, each with the same exact data for safety. I spoke to Dell and they said it is definitely possible. I do not want to affect my c or d drives at all. So, my question is: What software is super simple to use in order to implement raid 1 on the two new identical drives?
0
I have following version of eclipse IDE installed in my computer:
Eclipse IDE for C/C++ Developers
Version: 2018-09 (4.9.0)

I created a workspace.  There are number of Templates for New C / C++ Project.
I need to import very large 'C' source code files into my project.  I won't be compiling code in eclipse.  I'll just be navigating source code.
Which Project template should I select?  Is there a way to create project without selecting a project template?
0
Actually the file descriptor table is not a real table. It's just an array of pointers to the "open file table" (struct file). But let's say we will see it as a table. What are the columns? For example:

FD   | Pointer to "open file table"
----------------------------------
...  | ...

In short, that's the question. I see a lot of different figures on the internet, but they are all different. For example, see:

http://faculty.winthrop.edu/dannellys/csci325/10_shared.htm
There they have a column "fd flags" (read/write), but I would think that this column is part of the "open file table" and not part of the "file descriptor table". See for example: http://man7.org/linux/man-pages/man2/open.2.html


       A call to open() creates a new open file description, an entry in the
       system-wide table of open files.  The open file description records
       the file offset and the file status flags (see below).  A file
       descriptor is a reference to an open file description; this reference
       is unaffected if pathname is subsequently removed or modified to
       refer to a different file.  For further details on open file
       descriptions, see NOTES.

       The argument flags must include one of the following access modes:
       O_RDONLY, O_WRONLY, or O_RDWR.  These request opening the file read-
       only, write-only, or read/write, respectively.
0
I'm trying to investigate a problem with resource files generated by Google Omaha. These resource files contain a place-holder token (%1!s!), which is substituted with branding details during the build process. There are numerous language resource files that contains string tables and this

Here is an example string: "%1!s! some arbitrary text"

Where %1!s! is a place-holder for some substitution text?

My question: is this place-holder substitution mechanism a standard part of the Windows resource file mechanism? If so, can someone please either explain how it works? Where does it get the text used to substitute the place holder? I'm assuming the place-holder works similar to place-holders in printf? If so, how does it know which text token to replace this with? If this is not a standard resource file mechanism, does anyone have a clue as to how Omaha does this during the build process?

Many thanks.

Note: I'm not looking for suggestions to use a different approach. This is how Omaha does it and I just need to understand how this works. Thank you.
0
See: https://www.kernel.org/doc/Documentation/filesystems/vfs.txt

Dentries live in RAM and are never saved to disc:

A directory is also a file (special file). The contents of a directory consists of:

.           inode-number-current-directory
..          inode-number-parent-directory
filename_1  inode-number-A   
filename_2  inode-number-B
et cetera...

Open in new window


Usually this data is stored in data block(s). I say "usually" because some systems may store this in the directory's inode (< 60 bytes). But usually the data is stored in data block(s). If you make an empty directory, then the contents are:

.           inode-number-current-directory
..          inode-number-parent-directory

Open in new window


Usually you will see something like this:

Blocks: 8

Open in new window


8*512=4096 bytes. So 4096 bytes in the form of data blocks are allocated on disk. A dentry is just a directory entry, so:

filename_1  inode-number-A

Open in new window


So dentries are stored on disk. Then how I have to see this sentence?

Dentries live in RAM and are never saved to disc:

If they would only live in RAM, then you will lose all your dentries if the computer restarts? And why they are not stored on disc/disk? A directory usually just shows 8 blocks, this means that it is stored on disk.

Do I make a mistake here or what's behind it?
0
dup2(int oldfd, int newfd);

Open in new window


This is an equivalent of:

close(int newfd);
dup(int oldfd);

Open in new window


By closing "newfd" first, it becomes the lowest-numbered unused file descriptor (normally). Because of that the oldfd is copied to newfd (dup system call). So far, everything is clear.

Now see: http://codewiki.wikidot.com/c:system-calls:dup2


dup2 is a system call similar to dup in that it duplicates one file descriptor, making them aliases, and then deleting the old file descriptor.

Actually I don't think the old file descriptor will be deleted?

See: http://man7.org/linux/man-pages/man2/dup.2.html

After a successful return, the old and new file descriptors may be used interchangeably.

If the old file descriptor will be deleted, then they would not say something like that. Is wikidot.com just wrong about this?
0
Acronis Global Cyber Summit 2019 in Miami
 Acronis Global Cyber Summit 2019 in Miami

The Acronis Global Cyber Summit 2019 will be held at the Fontainebleau Miami Beach Resort on October 13–16, 2019, and it promises to be the must-attend event for IT infrastructure managers, CIOs, service providers, value-added resellers, ISVs, and developers.

I'm trying to understand the structure of the open file table. During this search I'm reading things that look like (for me) they are in contrast with each other.

In a system there is a:

File descriptor table:
This table is located in user space and is associated with a certain process (per-process).

Open file table:
This table is located in kernel space and is associated with all processes (process-wide).

Entries in the file descriptor table point to the open file table. This all is clear. Now let's go to the structure of these tables. For example, see: https://elixir.bootlin.com/linux/v3.18/source/include/linux/fdtable.h#L24

struct fdtable {
        [...]
};

Open in new window


And:

/*
 * Open file table structure
 */
struct files_struct {
        [...]
};

Open in new window


Also this is clear. But now see for example: http://www.andrew.cmu.edu/user/gkesden/ucsd/classes/sp17/cse291-a/applications/ln/lecture5.html

Per Process File Information


struct files_struct { /* kept within task_struct (PCB) */
        [...]
};

Here they are talking about files_struct when it's about "per process file information". I don't understand this, because the open file table is process-wide. This is for example what they are saying:

The count variable tracks the number of files the process has open

But imagine ... two different processes point to the same entry in the open file table. I think …
0
My question is about a pipe/pipeline in Unix. And it's especially about the FD (File descriptor) numbers/integers associated with it.
This is what I would expect:

  PROCESS A           PROCESS B
  0 stdin
  1 stdout -> pipe -> 0 stdin
  2 stderr            1 stdout
                      2 stderr

Open in new window


However, on the internet I'm reading different things.

For example, see: http://pubs.opengroup.org/onlinepubs/009696799/functions/pipe.html


Their integer values shall be the two lowest available at the time of the pipe() call.

Also see the images here: http://www.rozmichelle.com/pipes-forks-dups/#attachment_7362

Why new file descriptors are created? Why they don't use stdout (1) of the parent process? They could just redirect this existing
file descriptor (1/stdout) to the pipe. Do I miss something?
1
Please provide reference(s) that git doesn't require system administration.

Earlier today I asked question is there a version control system that doesn't require system administration.  
Expert answered Git.

I could google this information.  Please provide some links that confirm that git doesn't need system administration.
0
Hi I am trying make a deep copy of the structure below which will contain the decoded video frames and copy to a new element in a vector without each previous element being overwritten.
The structure below is being populated as the memory in debug mode is increasing as expected with each pass of the while loop.
struct YUV_Buffer
 {
mfxFrameSurface1  *mSurface;
YUV_Buffer(mfxFrameSurface1 *pBuf = { 0 })
    : mSurface(new mfxFrameSurface1[sizeof(mfxFrameSurface1)])
{
    memcpy(mSurface, pBuf, sizeof(mfxFrameSurface1));
}

YUV_Buffer(const YUV_Buffer& YuvBuf) 
 : YUV_Buffer(YuvBuf.mSurface)  
{}

YUV_Buffer& operator = (YUV_Buffer YuvBuf) {

    std::swap(mSurface, YuvBuf.mSurface);
    return *this;
}

~YUV_Buffer() {
        MSDK_SAFE_DELETE_ARRAY(mSurface);
}
  };

Open in new window

I am calling the structure and copying the elements into the vector with each iteration of the while loop "mfxFrameSurface1 pVPPSurfacesOut[nSurfIdxOut]" contains all the information regarding the decoded video frame I need to copy pVPPSurfacesOut[nSurfIdxOut] to the vector mBuffer.push_back(root) using a deep copy so the data that the pointers in the structure are pointing to are also copied but what is actually happening is the last frame processed is overwriting all previous elements in the vector. Each time the loop passes like this: I have removed the code that is decoding each frame as its no relevant I just need to work out why the elements are getting overwritten in the vector
while(1){
std::vector<YUV_Buffer> mBuffer;
YUV_Buffer root(pVPPSurfacesOut[nSurfIdxOut]);
mBuffer.push_back(root);
}

Open in new window

each iteration of the while loop populates pVPPSurfacesOut[nSurfIdxOut] structures which contain pointers with video information like height width buffersize … and the video data its self in a NV12, YUV420 colour space, I need to access each frame from the vector mBuffer but when I try to access the vector mBuffer[0]… Im getting the last frame copyed to the vector.

Regards Nigel
0
I have code to allow me to right click by mouse to bring to me menue of copy and past and delete


And have other to do copy and past but by key board ctrl c and ctrl v

As attached photo


I need to bind right click mouse to bring the code if ctrl c and ctrl v
0
what is the best tool to do profiling for c++ multi threaded server daemon on Linux?

Complied program with -pg and the tried with gprof/gmon.out. Couldn't find call graph as per functions mentioned in my program. It has shown all low level api's call graph like string internals, memory allocations..etc.

Can someone suggest how to get call graph from gmon.out for multi threaded server daemon.

Any other tool(s)?
0

C

22K

Solutions

13K

Contributors

C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, so it has found lasting use in applications that had formerly been coded in assembly language, including operating systems as well as various application software for computers ranging from supercomputers to embedded systems. It is distinct from C++ (which has its roots in C) and C#, and many later languages have borrowed directly or indirectly from C.

Top Experts In
C
<
Monthly
>