Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x

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

My large 'C' language code is in Linux Server.

Which Linux Editor should I use to edit and navigate my source code?

I need to use powerful editor that has powerful source code navigation.  For example, from function call, one keystroke will navigate to function definition.  From 'C' source file, one keystroke will open the include file.

There should be comprehensive information to  learn the editor from book or other sources.

From windows computer, I telnet to Linux Server.  

The folder structure that contains my source code is in my home directory.
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Hi,

Can someone please give me a link to a book on KCML Kerridge C Macro Language (KCML) and any info on how to develop in it please.

Started working for a company that uses it - thanks!
0
I migrated an SSD to a larger SSD using Macrium Reflect.   Now there is a large amount of unallocated space on the larger SSD.   How can I expand the C volume to use this space?
0
Can we make our keyboard into a mini piano by using c language
0
Somewhere along the line, about when OOP came along, I was diverted into doing other things.  So, I lack the "cultural refinement" that must have come along with it.
I've written programs in C, C++, VBA, C#, and Fortran (of whatever recent vintage) but, I must admit, quit in starting on C# because there were all those class names that had no meaning for me.  I couldn't even debug an example program as a result!

I think I understand the general concepts - so that's not it.
It's the specifics that are elusive.
I've seen the same thing in VBA but seem to have been able to get things done.  It was sort of like "programming by example" as in "copy & paste".

I've researched it a bit but don't seem to find the answer.  So:
What is the key to understanding the Classes, what they're called and what they do, so that one can be relatively productive?  Does this come by osmosis?
It must be something like a dictionary....
Or, if the proper term is other than "Classes", can you enlighten me a bit please?
0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "assignment.h"
#include "list.h"
void ex7() {
    node_t *a=Initialize('1');
    node_t *b=NULL;
    PrintList(a);
    InsertFirstList(&a, 'V');
    InsertFirstList(&a, 'M');
    PrintList(a);
    InsertLastList(&a, 'C');
    PrintList(a);
    SplitList(&a, &b, 2);
    PrintList(a);
    PrintList(b);
    DeleteFirstList(&a);
    PrintList(a);
    InsertLastList(&a, 'G');
    DeleteLastList(&b);
    PrintList(b);
    InsertLastList(&b,'0');
    PrintList(b);
    InsertLastList(&b, '1');
    PrintList(b);
    MergeList(&a,&b);
    PrintList(a);
    char target='G';
    printf("Count '%c': %d\n",target, SearchList(&a,target));
    target='1';
    printf("Count '%c': %d\n",target, SearchList(&a,target));
    FreeList(&a);
}
node_t *Initialize(char ch) {
    node_t *head;
    head=(node_t*)calloc(1,sizeof(node_t));
    if(head==NULL){
      fprintf(stderr,"Failed to assign memory!\n");
      exit(-1);
    }
    head->next=NULL;
    head->ch=ch;
    return head;
}
void PrintList(node_t *head) {
    node_t *temp=head;
    printf("***Print Linked List***\n");
    while(temp!=NULL) {
      printf("%c ",temp->ch);
      temp=temp->next;
    }
    printf("\n****Print Finished****\n\n");
}
void FreeList(node_t **head) {
    node_t *tmp=NULL;
    node_t *pHead=*head;
    while(pHead->next!=NULL) {
      tmp=pHead;
      pHead=pHead->next;
      free(tmp);
    }
    free(pHead);
}
bool …
0
The  following  code  is  for  gps  gsm  module.The  compiled  hex  code  is  pushed  to  microprocessor.
While  compiling the  below code  we  get  unknown  variable  error  for  following  variables UCZS0, UCZS1
Please  guide  us  for  same.

//GPS and GSM Based Vehicle tracking system
#define F_CPU 12000000			//12Mhz
#include <avr/io.h>			//Header file for AVR device specific I/O Definitions.
#include <avr/pgmspace.h>		//Header file for incorporating program space string utilities.
#include <util/delay.h>			//Header file for incorporating delay routines.
#include<inttypes.h>


#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

void WaitMs(unsigned int ms);		

void usart_init();
unsigned int usart_getch();
void usart_writech(unsigned char data);
void usart_message(unsigned char *var);

unsigned char value,i,lati_value[9],lati_dir, longi_value[10], longi_dir, final_message[30];
unsigned char deg = 0xB0;

int main()
{

DDRC=0x00;
PORTC=0xff;

    usart_init();

    while(1)
	{
	 a:
	 value=usart_getch();
	 if(value=='$')
	 {
		
	value=usart_getch();
		if(value=='G')
	{
	value=usart_getch();
	if(value=='P')
	{
	value=usart_getch();
	if(value=='G')
	{
				
	value=usart_getch();
	if(value=='A')
	{
	value=usart_getch();
	if(value==',')
	{
	value=usart_getch();
	while(value!=',')
	{
	value=usart_getch();
	}
	
	for(i=0; i<9; i++)
	{

	lati_value[i] = usart_getch();

	}
	value = usart_getch();
	
	lati_dir=usart_getch();
	

Open in new window

0
I have the following code:

#include<stdio.h>
char checkInput0(void);

int main() {
  char output;
  output = checkInput0();
  printf("The output is %c", output);
}

char checkInput0(void){
  char option0 = '\0',check0;
  char c;
    
  do{
    printf("Please enter the your choice of A or B: ");
    scanf("%c %c",c ,option0);  
    if(c || option0 != 'A' && 'B' ){
      while((check0 = getchar()) != 0 && check0 != '\n' && check0 != EOF);
      printf("[ERR] Please enter A or B.\n");
    }else{
      break;
    }
  }while(1);
  return option0;
}

Open in new window


and it prompts the user to input something but regardless of the input, I get a segmentation fault.
What I would like the program to do is to Prompt the user to Please enter  your choice of A or B: and if the User enters an A or B it would output: The output is <Their choice>. anything else is entered it should print the following message: [ERR] Please enter A or B.\n.
I can't seem to get it to work.
All help Will be greatly appreciated.
Thanks in advance
0
I have a friend who wants to learn to make video games.

I was wondering what to teach him , I was thinking of starting out with Dennis Ritchie’s “The C Programming language”

He wants to make a game within the next two years. That’s his goal.
0
Hello,

Can someone tell me why I am getting Lvalue required error in the getsmtdata function at the lines where I am trying to set the Attribute name ?

struct Attribute
{
char id;
char name[40];
char status[2];
char value;
char worst;
char raw[6];
};

struct SmartData
{
struct Attribute Attributes[30];
char ExecutionStatus;
};

void getdsmtdata(struct SmartData *smtdata, char *fn)
//This function opens the smtdata file and extracts the attribute data.
{

FILE *input;
char junk;
int count;

printf("in getdinfo(), fn = %s", fn);
//ch = getch();
if((input = fopen(fn, "rb")) != NULL)
	{
		fseek(input, 2, SEEK_SET);

	  for(count = 0; count<30; count++)
	  {
			junk = fgetc(input);
			switch(junk)
			{
				case 1:
					smtdata->Attributes[count].name = "Read Error Rate";
					break;
				case 2:
					smtdata->Attributes[count].name = "Throughput Performance";
					break;
				case 3:
					smtdata->Attributes[count].name = "Spin Up Time";
					break;
				case 4:
					smtdata->Attributes[count].name = "Start/Stop Count";
					break;
				case 5:
					smtdata->Attributes[count].name = "Reallocated Sector Count";
					break;
				case 7:
					smtdata->Attributes[count].name = "Seek Error Rate";
					break;
				case 8:
					smtdata->Attributes[count].name = "Seek Time Performance";
					break;
				case 9:
					smtdata->Attributes[count].name = "Power On Hours";
					break;
				case 10:
					smtdata->Attributes[count].name = "Spin Retry Count";
					break;
				case 12:
					

Open in new window

0
Technology Partners: We Want Your Opinion!
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

I have written down a simple c program related to a medical store which is saving medicine name, dose, stock and where it is stored in a rack. Here is a code.

#include<stdio.h>
#include<string.h>
#include<dirent.h>
#include<stdlib.h>

// Global variable
char *databasePath;

/* function declaration */
void InitConfiguration(FILE *fWrite, FILE *fRead);
void GetUserName();
void ShowMenu();
struct Medicine GetMedicine();
void SearchMedicine(FILE *fWrite, FILE *fRead);
void AddCart(FILE *fWrite, struct Medicine medicine);
void UpdateMedicineStock(FILE *fWrite, struct Medicine medicine);
void AddMedicine(FILE *fWrite);
void SaveMedicine(FILE *fWrite, struct Medicine medicine);
void ConvertToLowerCase(char* string);
struct Medicine SearchMedicineInDatabase(FILE *fRead, struct Medicine medicine);
char* GetStringFromInt(int value);
char* GetStringFromLong(long value);

struct MedicineInfo
{
    long int cupboardNo;
    long int rackNo;
    long int boxNo;
};

struct Medicine
{
    char name[50];
    char dose[15];
    long int stock;
    struct MedicineInfo medicineInfo;
};

void main()
{
    FILE *fWrite, *fRead;
    InitConfiguration(fWrite, fRead);

    // Show welcome message and get user's name.
    GetUserName();
    ShowMenu(fWrite, fRead);

    getch();
    free(databasePath);
}

void ConvertToLowerCase(char *string) {
    int i;
    for (i = 0; i < strlen(string); i++)
    {
        if (string[i] >= 'A' && string[i] <= 'Z') {
            string[i] = string[i] + 32;
 

Open in new window

0
Hi,

Can an ASP.NET Core app support reading and writing to an access database? BTW this would be a ASP.Core app running on a Linux host.

https://blogs.msdn.microsoft.com/dotnet/2016/11/09/net-core-data-access/

I assume it cant but wanted to double check in case there is another way.

Thanks,

Ward
0
Constraint: Cannot change from C++03 or C-88.

After some online search, I wrote the following program to see how to run a class non-static member function in a pthread via a static member helper. But I got the wrong answer. According to breakpoints, the DoSomething constructor is called once; yet on the 2nd call to doSomething, the initial values of val1 and val2 are set to 100, 200.0, respectively. Granted, I set the members of an internal struct to those values, but not to the class data members.

So, how did that happen; how do I get the args.retval return value from the pthread to end in 5 + 16 = 21 + a multiple of 100.
// header
class DoSomething
{
public:
	DoSomething(int v1, float v2)
		: val1(v1), val2(v2) {
	retval = val2 - val1;
	}

	float* doSomething(int v1, float v2) 
	{
		val1 += v1;
		val2 += v2;
		retval = val1 + val2;
		return &retval;
	}

	struct v1v2_s
	{
		int v1;
		float v2;
		float retval;
	};

	static
    void* DS_helper(void* args)
	{
		int v1 = ((v1v2_s*)args)->v1;
		float v2 = ((v1v2_s*)args)->v2;
		((v1v2_s*)args)->retval = *((DoSomething*)args)->doSomething(v1, v2);
		return args;
	}

private:
	int val1;
	float val2;
	float retval;
};

Open in new window

#include "DoSomething.h"

int main()
{
	DoSomething DS(2, 9);

	DS.doSomething(3, 7);

	DoSomething::v1v2_s args = {100, 200.0};

	pthread_t t;
	pthread_create(&t, NULL, DS.DS_helper, &args);
	pthread_join(t, (void**)&args);
	float res = args.retval;
	return 0;
}

Open in new window


If you could correct the existing code w/o trying to revamp the whole approach, I would appreciate that. (After this is done, then, sure, revamp the whole approach.)
Thanks in advance.
0
This isn't really a question; rather, it is a puzzle!!!

Please note, this is NOT an assignment of any kind (check my profile if you are unsure as to my tenure on the site). The idea is to spark some activity in the C/C++ topic areas and to have a little fun. Points will be awarded to the expert(s) who provide the most interesting solution. The idea is to have a little fun, promote discussion and have something interesting to think/talk about.

If this goes well, I plan on doing one of these types of puzzle questions on a regular(ish) basis. I would like to see expert colaboration, rather than experts just going gun-ho to get points. I will consider colaboration between experts when I finally award points. I will close this question once I believe it has reached a natural conclusion (ie. no futher productive activity).

So, let's start with the first puzzle. It's one that has been set many times before and I'd be interested in seeing different approaches to solving it. Please don't just search Google and copy/paste. I promise I will check and any plaigirised answers will be ignored (and probably deleted).

Let's go...

Your job is to write a program that, when run, outputs it's own source code (including comments) such that if the output was fed back into a compiler, built and run it would do exactly the same thing as the original program. The output must be word for word identical to the original source code, such that performing a diff between the original source …
1
I have a tcp server running on linux and bound to unix domain socket

I want to allow (give permission ) to another process (running as a user) to connect to the server using the same domain socket.

How Can I achieve that ?


Thanks
0
--------------------Configuration: StockCharter - Win32 Release--------------------
Compiling...
StdAfx.cpp
C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\objbase.h(435) : error C2664: 'memcmp' : cannot convert parameter 1 from 'const struct _GUID *' to 'void *'
        Conversion loses qualifiers
C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\objbase.h(459) : error C2664: 'memcmp' : cannot convert parameter 1 from 'const struct _GUID *' to 'void *'
        Conversion loses qualifiers
C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\memory.h(68) : error C2733: second C linkage of overloaded function '_memccpy' not allowed
        C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\memory.h(68) : see declaration of '_memccpy'
C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\memory.h(69) : error C2733: second C linkage of overloaded function 'memchr' not allowed
        C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\memory.h(69) : see declaration of 'memchr'
C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\memory.h(70) : error C2733: second C linkage of overloaded function '_memicmp' not allowed
        C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\memory.h(70) : see declaration of '_memicmp'
C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\memory.h(76) : error C2733: second C linkage of overloaded function 'memcmp' not allowed
        C:\Program Files …
0
I wrote the attached code with the intention to get 42 as the output but I instead get an asterisks (*) I know that 42 is the ACII value of an asterisk. Please look at my code and see something I might have missed. The program is in C using the <unistd.h> library, I have to use the unistd.h and not the stdio.h for this code.

[code]
#include <unistd.h>

void      ft_putchar(char c)
{
      write(1, &c, 1);
}

void    ft_putnbr(int nbr)
{
    write(1, &nbr, 1);
}

void      ft_ft(int *nbr)
{
      *nbr = 42;
}

int      main(void)
{
      int a;
      int *ptr;
      char c;

      a = 7;
      ptr = &a;
      ft_ft(ptr);
    ft_putnbr(a);
      ft_putchar('\n');
}
/code]
0
Due to security concerns related to updates not being applied to third-party software libraries, we are trying to replace as many of these as possible with functionality provided by the operating systems and are looking into options with compression. Are there any common compression formats that both Linux and Windows understand and provide C or C++-callable functions to programs to compress to and decompress from using only the APIs provided by the operating systems as installed? Thanks for any information!
0
Good morning,
im getting the error show in the picture bellow, I've seen other examples and it should work, am I doing something wrong?

error.png
my model
 public class Usuario
    {
        public int Id { get; set; }
        
        [Required]
        [StringLength(80)]
        public string Nombres { get; set; }

        [Required]
        [StringLength(40)]
        [Display(Name ="Primer apellido")]
        public string PrimerApellido { get; set; }

        [Required]
        [StringLength(40)]
        [Display(Name = "Segundo apellido")]
        public string SegundoApellido { get; set; }

        [Required]
        [StringLength(30)]
        public string Cedula { get; set; }

        [Required]
        [Display(Name = "Fecha nacimiento ")]
        public DateTime FechaNacimiento { get; set; }

        [Required]
        [StringLength(5)]
        public string Rh { get; set; }

        [Required]
        [StringLength(10)]
        public string Genero { get; set; } 

        [Required]
        [StringLength(200)]
        [Display(Name = "Dirección")]
        public string Direccion { get; set; }

        [Required]
        [StringLength(200)]
        [Display(Name = "Barrio")]
        public string Barrio { get; set; }

                
        public Municipio Municipio { get; set; }

        [Display(Name = "Municipio")]
        public int MunicipioId { get; set; }
        

        [Display(Name ="Telefono fijo")]
        public string 

Open in new window

0
Concerto's Cloud Advisory Services
LVL 5
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

I have not done unit testing for a little while and expect a test upcoming to verify I can quickly write unit tests.

Suggestions of the thing I should be practicing?

Unit tests generate their own mock data, but I doubt a test would include me setting up a mocking framework. I think hard coded lists of objects would be the ideal method, on a coding test.

I assume the object wold be written already for me (it's going to be a 15 minutes test only)

I would create an instance of the object, review the parameter list for that method being tested...

I could create multiple sets of test data. Would a switch statement be appropriate for this kind of knock em out unit test? I could iterate through and handle a handful of test conditions...


Assertions are key.

Once it fails, the unit test fails. I need to be sure the specific test condition which failed the assertion is visible in the console.

Am I approaching this test the right way?

Suggestions?

Thanks.
0
#include <stdio.h>

int main (void)
{
    printf ("Hello, world!\n");
    return 0;
}


what does the  "\n" below mean ?

printf ("Hello, world!\n"
0
I am working on a project here where I need to have a rolling average of a 2D array of numbers. The rolling average should average across a rolling "window" size of 8. I have a simple example here to demonstrate, but the idea is that with each new 2D array (a new data scan), that array will be copied into the rolling buffer that I have set up as a 3D array where the 3rd dimension is of size of the rolling window. With the current code I have below, I'm not getting the output I expect. To check if its working, I am just printing out the same position in each 2D scan across all scans of the rolling buffer, but I am not getting what I expect and I'm struggling to find issue in the code. Am I even going about this correctly? Thanks for any help. output attached below.

output from current code
I would expect an output that looks like:
0
1 | 0
2 | 1 | 0
3 | 2 | 1 | 0
and so on ...


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BlockCopySample
{
    class Program
    {

        static void Main(string[] args)
        {

            RollingAverager RA = new RollingAverager();

            for (int i = 0; i < 25; i++)
            {
                RA.addValue(i);
                RA.PrintBuffer();

                System.Threading.Thread.Sleep(1000);
            }
        }
    }



    class RollingAverager
    {
        const int INT_SIZE = 4;
        const int DOUBLE_SIZE = 8;

    

Open in new window

0
How to do Windows 10 Microsoft Visual Studio 2010 Multihreading (but not .net and not MFC) in C++03.
I don't have 3rd party tools like openMP, etc. Just have native Microsoft API (I hope).

I searched around and found an answer to the following 3 questions (included in my post below):
When I search online, I found this:
Multithreading with C and Win32
https://msdn.microsoft.com/en-us/library/y6h8hye8.aspx

But I am in a 64-bit environment.

a. Is there a Microsoft 64-bit (non .NET) multithreading capability? If not, then I will proceed with 32-bit API. But the applications being developed are 64-bit.

b. Is it OK to use Win32 in the 64-bit application?

c. If it is OK, are there any performance penalties or any other downsides in doing this?

If you explain things to me, and use POSIX terminology and their Microsoft equivalent, that would help. I have done Linux multithreading. I am brand new to Microsoft development (other than using VIsual Studio 2010 for relatively simple single-threaded programs).

Unfortunately, I cannot use C++11 or Boost because they will not be installed for awhile (anywhere between 6-90 months is my best guestimate).

I am unable to install anything to enhance my development. (I know - this sucks.)

1. I would appreciate if you could provide good learning examples and help me with some questions on the basics if they arise.

Here are some links that I have just  quickly …
0
I am trying to create a C function that will return a string as BSTR so I can use it in VBA and i have broken down into its absolute simplest form. This just accepts one double (I will eventually need 3 doubles). I just need to know how to convert myStr to BSTR and then make it available to a VBA call.
double _stdcall square(double *x)
{
	char myStr[] = "Hello World";
	return *x * *x;
}

Open in new window


In arriving at the above I found found the following code would crudely give me a string back but only the first part does so correctly.  
STDAPI GetMyCode(BSTR in, BSTR out, int cch, double *int1, double *int2, double *int3)
{
	LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_LINGUISTIC_CASING | LCMAP_UPPERCASE, in, SysStringLen(in), out, cch);
	char myStr[60];
	strcpy_s(myStr, 60, out);
	return S_OK;
}

Open in new window


When I convert this code into a DLL and call it with the following VBA, the result is "HÉLLO WORLD" - Absolutely perfect.  
GetMyCode StrPtr("héllo world"), StrPtr(cch), 256, -32.12345, 115.11111, 23.5
debug.print cch

Open in new window

 However the part of the code that isn't compiling correctly is strcpy_s(myStr, 60, out); I assume because out is a BSTR and myStr is char. So I need to work out how to get the value of myStr out of the function into VBA.  Can anyone help me figure out

By way of background:
The function I want to eventually create from this will only take 3 doubles as parameters - the other 3 I have used in this demo are unnecessary.
Eventually myStr will contain a character string (I believe that's know as an array in C) that is somewhere between 9 and 60 characters long
It is that string that I will want to convert to BSTR and return to the VBA call.
But for now, all I need is to just get the above to work.
0
Hey there guys.

I have been given a chunk of C++ Code that I need to turn into assembly for 3 Processors.

The, 6805, DS89C420 & ARM7

Below is the code.
Any Help would be amazing.

void BubbleSort (void) {
 unsigned char tmp;
 int i, j;
 for (i=0; i<sizeof(Data)-1; i++) {
 for (j=0; j<sizeof(Data)-1-i; j++) {
 if (Data[j+1] < Data[j]) {
 tmp = Data[j];
 Data[j] = Data[j+1];
 Data[j+1] = tmp;
 }
 }
 }
 }
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.