Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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

Hi,
I would like a formula to find multiple max values with reference to date.
example "Find the top two values for the day.
whereby I can adjust to find top value, top two. top three, etc.
Please refer to attached spreadsheet and place formula in Col C
Many thanks

Ian
Max-Number-Daily.xlsx
0
Industry Leaders: We Want Your Opinion!
Industry Leaders: 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 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
What options are there to protect a web service from a DOS attack?

IF the web service were accessed only by my Objective-C iPhone application, and nowhere else, is this web service protected by the "security through obscurity" model? Or, can hackers crack open the source code of the iPhone app, like Apple can?

What about if I put the URL to the web service into the SQLite database and encrypted the Path?

So, when my app needs to request information from the web service, it does a DB lookup in the SQLite database for the path to the web service. When it gets it, it decrypts it. Then, using a variable (in memory) only, it makes the web service call.

Does this protect from a DOS attack to that web service call?

Are there easier ways?

Will this work on Java for the Android?

What about on my website?

Thanks.
0
After almost two weeks trying to resolve this I am stumped at what I think is the final step. I just can't come to grips with how I can get a C Function to output a character string and I just don't know how to proceed. In summary I have a function that will generate the string I need

 main()
{
	char buf[60] = { '\0' };   // Set the max length of the final link string
	int ret = GenShortDroidMapUrl(-32.1458637, 115.8353645, (double)14, "my Place", buf, sizeof(buf) - 1);
	buf[ret] = '\0';
	printf("\n return of GenShortDroidMapUrl =  %s \n", buf);
	return 1;
}

Open in new window

When I run this code it displays the code I am after perfectly, but what it is displaying is the value of buf, which is destroyed as soon as this code is run.

I have also been able to create a DLL from it and it builds without errors. In doing so I left out Main() because what I want to do is make a call to this code from MS Access to get the output. In access I added the following which I believe should enable me to make a call to the function GenShortDroidMapUrl and get the response back

Public Declare Function GenShortDroidMapUrl _
    Lib "D:\Rob\source\repos\Ge0Make\Debug\Ge0Make.dll" _
    (ByVal latit As Double _
    , ByVal longit As Double _
    , ByVal zoom As Double _
    , ByVal locName As String _
    , ByRef newurl As String _
    , length60 As Integer)

Open in new window


What I don't know is how to make my C Function output the value of buf when I make the call. I won't put all the code but the GenShortDroidMapUrl function code is as follows. Clearly it returns an int whereas I actually want it to return the string contained in the array buf. And I need it to survive long enough to be handed back to the calling function. I have seen this kind of code work with numbers but I can't get my head around how to do it with a string. Am I missing just a few, short, simple changes that an Expert can help me with, or do I need to employ a C programmer to help me get this DLL working?


Open in new window

0
I want to install WAMP on my laptop to work on a Wordpress site locally to be moved to a server later.  I have all the latest Windows updated and Visual Studio 2017 updates but when I go to wampserver.com/en and download, I get warnings before installing to make sure I am up to date in the redistributable packages vc9, vc10, vc11, vc13, and vc14.  Do I need to install all of those. There is now vc15 which is backward compatible with vc14.  I'm just looking for the easiest and quickest way to set up my WAMP server so I can install wordpress.  I have never installed WAMP or Wordpress on this computer so other than installing other software, I'm really building from scratch.  Also, I considered installing the C# version of WAMP since I work with C#.  Is there any advantage or disadvantage to doing that since I plan to run Wordpress?  Feedback?
0
I have found a C function that I think will provide the results I need but I have zero experience with C. For the sake of explanation, basically I want to input something like  MapsWithMe_GenShortShowMapUrl(-32.1458637, 115.8353645, 14, "my Place") and have it return the full URL formated as needed by the app it's associated with.  

I have taken the C code and tried to incorporate it into a Visual Studio 2017 project as a starting point. I have attached a copy of the entire code and what I am trying to work out is what it is expecting from the buf and bufsize parameters in the line:
   int MapsWithMe_GenShortShowMapUrl(double lat, double lon, double zoom, char const * name, char * buf, int bufSize)
Can anyone help me figure out what parameter it is asking for?

#include <stdio.h>

void main()
{
	
	printf(MapsWithMe_GenShortShowMapUrl(-32.1458637, 115.8353645, 14, "my Place", 1, 1));
}

//#include "api-client.h"
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

// Max number of base64 bytes to encode a geo point.
#define MAPSWITHME_MAX_POINT_BYTES 10
#define MAPSWITHME_MAX_COORD_BITS (MAPSWITHME_MAX_POINT_BYTES * 3)



char MapsWithMe_Base64Char(int x)
{
	assert(x >= 0 && x < 64);
	return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"[x];
}

// Map latitude: [-90, 90] -> [0, maxValue]
int MapsWithMe_LatToInt(double lat, int maxValue)
{
	// M = maxValue, L = maxValue-1
	// lat: -90                

Open in new window

0
Hello ,


I want to create a function to remove an element from IP4Map with matching ip4 but i could not succeded should any body help me ?



typedef struct IP4SYN{
     unsigned int ip4;
     unsigned int count;
	 unsigned int source_port;
	 unsigned int dest_port;
	 unsigned int dest_IP;
     long int SYN_Son;
     size_t s;
     size_t n;
} IP4SYN;

typedef struct IP4Map{
      IP4SYN * a;
      size_t s;
      size_t n;
} IP4Map;
unsigned int AddIP4ToMap(IP4Map * ip4map,unsigned int ip4,unsigned int source_port,unsigned int dest_port,unsigned int dest_IP){
       unsigned int pos =  0;
       if (ip4map->n >= ip4map->s)
       {
              ip4map->a = (IP4SYN *)krealloc( ip4map->a, ip4map->s+blocksize,GFP_NOWAIT);
              memset(&ip4map->a[ip4map->s], 0, sizeof(IP4SYN)*blocksize);
              ip4map->s += blocksize;
       }
       pos = FindIP4InMap(ip4map, ip4,source_port,dest_port,dest_IP);
       if (ip4map->n > pos)
       {
             if((ip4map->a[pos].ip4==ip4)&&(ip4map->a[pos].source_port==source_port)&&(ip4map->a[pos].dest_port==dest_port)&&(ip4map->a[pos].dest_IP==dest_IP)){
					ip4map->a[pos].SYN_Son=Zaman_MS();
					return ++ip4map->a[pos].count;  // increment counter
             }
             else  // shift entries 1 to the right from pos 
             {
                    unsigned int shift = (ip4map->n - pos)-1;
                    if (shift > 0)
                    {
                          memmove(&ip4map->a[pos+1], 

Open in new window

0
Hello  ,

I am trying to read an hex part as given below i am hitting firs 08 with if it is ok than getting the size with 0a -> 10 it is also ok but i couldnot get into a variable .


  08 0a 59 97 a9 ef 07 29 c3 28                    

Open in new window


                        if (kind == 8) {
					p++;
					uint8_t size = *p;
					p++;
					TS=(*(uint32_t *)p)
					//printk(KERN_ERR "4. TS %d ",(*(uint32_t *)p));
					p += (size-2);
				}

Open in new window

0
Hello ,

Normally we really love of using std::map on userspace but in kernel space i could not find a dynamic memory allocated map structure. Any body knows a good example how to do this job on kernel space ?

Thank you
0
Concerto's Cloud Advisory Services
LVL 4
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.

Hello ,

Is there any library to trace / ping an ip or a better / faster way to get the ttl of an ip address ?
0
With the help of some Experts on other questions I have been led to the following links that generate a URL that will launch maps.me app on Android and iOS devices to a desired GPS Lat, Long, Name and Zoom level. (e.g. -32.1458637,115.8353645, "My Place", 14) . I have a need to generate this URL from MS Access.

Two questions:
1) Is there is any way I could use or set up the existing C function or API to enable me to make a call from MS Access and have it return the URL instead of trying to translate the function into VBA?
2) It would also be useful if I could set it up so I could make a JSON call to it from another app so is there a way I can do that.

    https://www.programcreek.com/java-api-examples/index.php?source_dir=cgeo-master/mapswithme-api/src/com/mapswithme/maps/api/MwmRequest.java           
or
https://github.com/mapsme/omim/blob/master/api/src/c/api-client.c
0
Hello ,

I want to use given struct in a map as this : std::map<Web_Dumper, int> http_dumper;


but i am getting errors, where should i do mistake ?

struct Web_Dumper
{
    IP4 ip;
    const std::string Agent;
    const std::string Version;
    const std::string Host;
    const std::string Path;
    const std::string Ulke;
    long int Tarih;
    Web_Dumper(IP4  szip,const std::string sAgent,const std::string sVersion,const std::string sHost,const std::string sPath,const std::string sUlke,long int sTarih) : 
    ip(szip), Agent(sAgent) , Version(sVersion), Host(sHost), Path(sPath),Ulke(sUlke), Tarih(sTarih){}
    friend bool operator<(const Web_Dumper & ipt1, const Web_Dumper & ipt2) { return std::make_pair(ipt1.ip,ipt1.Agent,ipt1.Version,ipt1.Host,ipt1.Path,ipt1.Ulke,ipt1.Tarih) <  std::make_pair(ipt2.ip,ipt2.Agent,ipt2.Version,ipt2.Host,ipt2.Path,ipt2.Ulke,ipt2.Tarih); }
};

Open in new window




AnomalyDetector.c: In function ‘bool operator<(const Web_Dumper&, const Web_Dumper&)’:
AnomalyDetector.c:1311:173: error: no matching function for call to ‘make_pair(const IP4&, const string&, const string&, const string&, const string&, const string&, const long int&)’
     friend bool operator<(const Web_Dumper & ipt1, const Web_Dumper & ipt2) { return std::make_pair(ipt1.ip,ipt1.Agent,ipt1.Version,ipt1.Host,ipt1.Path,ipt1.Ulke,ipt1.Tarih)
                                                                                                                                   

Open in new window

0
Hello ,

I want to appy a system command with arguments from variables but i could not find an example any body has experience about this ?


This is what i want to do
system("/bin/bash  /etc/a.sh   %d %d",val1,val2);
0
I am testing the authorized.net captureprviouslyauthorizedamount i can get an transaction type as authorization only but can not get the capture amount. it is saying invalied transaction id. Do i need to change from test to production and than cancel the credit card amount
0
How to write test case for c program
0
Hello ,

We want to create fork subroutines on runtime and let it die after 180 seconds. But ;
We do not want to let the mirror all global variables that should cause high memory usage on the system , we just want to pass the variables to the fork and it will do a few small jobs then will end it self after 180 seconds is it possible to isolate from the other app ?
As far as i know when a fork start it completely clone the existing maps / arrays etc. and work in another road.
0
Hello ,

For a project we are using ip.h library of the linux.
As far as i check the library , http://www.cse.scu.edu/~dclark/am_256_graph_theory/linux_2_6_stack/linux_2ip_8h-source.html  , i could not find a way to check Window size , is there any way to read complete packet hex with this library and get the window size of packet hex like given below :

			long dec_Window_size = std::stol (packet_hex.substr(96,4),nullptr,16);

Open in new window

0
How should i solve this :)


	std::string RANGE ;
			std::stringstream RANGEstream;
			for (std::pair<long int, int> element : TTL) {
				RANGEstream <<  element.first;
				RANGE = RANGE + RANGEstream;
			}

Open in new window



dinleyici.c:352:19: error: no match for ‘operator+’ (operand types are ‘std::string {aka std::basic_string<char>}’ and ‘std::stringstream {aka std::basic_stringstream<char>}’)
     RANGE = RANGE + RANGEstream;
                   ^

Open in new window

0
Concerto Cloud for Software Providers & ISVs
LVL 4
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Hello ,


Is there any body know a way to send live message to kernel module like the given below. I want to send a message to it and let it write to logs the message
My message will be sended from the user space and the kernel module is working on kernel space




#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_INFO */

int init_module(void)
{
	printk(KERN_INFO "Hello world 1.\n");
	return 0;
}

void cleanup_module(void)
{
	printk(KERN_INFO "Goodbye world 1.\n");
}

Open in new window

0
on the C++2011 compiler why that warnings happens for this code part and how should i do the legal app.
(*((unsigned int*)&ip4[0]))




dinleyici.c: In constructor ‘IP4::IP4(const char*)’:
dinleyici.c:36:28: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   *((unsigned int *)&ip4[0]) = 0;
                            ^
dinleyici.c: In function ‘bool operator<(const IP4&, const IP4&)’:
dinleyici.c:44:96: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  friend bool operator<(const IP4 & ip1, const IP4 & ip2) { return *((unsigned int *)&ip1.ip4[0]) < *((unsigned int *)&ip2.ip4[0]); }
                                                                                                ^
dinleyici.c:44:129: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  friend bool operator<(const IP4 & ip1, const IP4 & ip2) { return *((unsigned int *)&ip1.ip4[0]) < *((unsigned int *)&ip2.ip4[0]); }
                                                                                                                                 ^
dinleyici.c: In member function ‘IP4::operator unsigned int()’:
dinleyici.c:51:67: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         operator unsigned int() { return (*((unsigned int*)&ip4[0])); }  // cast the pointer to low byte to unsigned int  }
                    

Open in new window

0
hello

static std::map<Log, int> Logmap_;
static std::map<Log, int> Logmap_new;


Is there any possible way to search in a hash table which has values like given below 16-24. char for 4F94CFAE  and put founded lines to Logmap_new from  Logmap_ with values



DC38E1AC9B89A0369F557CAA080045100104FC62400040069BD5257B628A4EAFCAF70016F273CA35B6FD50ED7F8D50180094CE830000BC2411DB2762C01F5AE797C64F94CFAE2833E406D8376DB4005717643E0DBA31A7D5BA073799AB93CEE4E22A357C
DC38E1AC9B89A0369F557CAA080045100338FC634000400699A0257B628A4EAFCAF70016F273CA35B7D950ED7F8D501800940CEE0000974CEDC48B7C50744D96523A13FBD77D4CCAE45BF24F9FB91E7B43600A7397E2DD9788F7E7837D69170BD5A94E83
A0369F557CAADC38E1AC9B8908004500004CCC3440003A06D2CB4EAFCAF7257B628AF273001650ED7F8DCA35B2B150182000D53900003068613A5E81D88EEB70EC9A0B45304A8266890A03CB36E112653052C767CCFEC9281625
DC38E1AC9B89A0369F557CAA08004510004CFC64400040069C8B257B628A4EAFCAF70016F273CA35BAE950ED7FB15018009413FA0000E1FC591EA86C2AEA5245848504E41776637B03D3261D943B020BA01464A715C32B4E4610
A0369F557CAADC38E1AC9B89080045000028014040003A069DE44EAFCAF7257B628AF273001650ED7FB1CA35B4CD50101FEFAC0D0000000000000000
A0369F557CAADC38E1AC9B89080045000028DDF640003A06C12D4EAFCAF7257B628AF273001650ED7FB1CA35B6FD50101FEEA9DE0000000000000000
A0369F557CAADC38E1AC9B8908004500002807BA40003A06976A4EAFCAF7257B628AF273001650ED7FB1CA35B7D950101FF9A8F70000000000000000

Open in new window

0
Hello ,

The given code below returns an answer as given at the bottom . I need to put each line into an array .  how should i do it ? I mean i need to build line in for i loop and then need to add to array.

Thank you


	for (int i = 0; i < (bpf_u_int32) pkthdr->caplen; i++) {
		printf("%02X%s", (uint8_t)packet[i], (i + 1)%2 ? "" : "");
	}
	printf("\n");

Open in new window



DC 38E1 AC9B 89A0 369F 557C AA08 0045 C002 40B1 6900 0040 01ED A925 7B62 8A3B C115 2403 0337 A600 0000 0045 0004 1846 F000 00FD 1199 FA3B C115 2425 7B62 8AC1 3B00 1704 0400 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00
A0 369F 557C AADC 38E1 AC9B 8908 0045 0004 1846 E900 00FD 11B0 6759 7DE1 0125 7B62 8A7D 5900 1704 0400 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00
A0 369F 557C AADC 38E1 AC9B 8908 0045 0004 1847 7600 00FD 1188 6C7E 94E3 5825 7B62 8A94 7E00 1704 0400 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00
A0 369F 557C AADC 38E1 AC9B 8908 0045 0004 1847 9100 00FD 1168 74B4 AECD 1B25 7B62 8AAE B400 1704 0400 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00
A0 369F 557C AADC 38E1 AC9B 8908 0045 0004 1847 8C00 00FD 1147 4C4D D055 2725 7B62 8AD0 4D00 1704 0400 

Open in new window

0
Hello ,

I got a code like the given below , there is no begin and end values but it enters the if statement different parts but i could not understand why or how , should somebody tell me how this values changes on incrementIp function

	
struct SharedData
{
	bool done;
	pthread_mutex_t mutex;
	unsigned int ip_ring[100];
	int begin;
	int end;
	void shared_data() { memset(this, 0, sizeof(SharedData));}
	void incrementIp(unsigned int ip4){
		
		pthread_mutex_lock(&mutex);
		if ((end+1)%100 == begin)
		{			
			pthread_mutex_unlock(&mutex);
			incrementIp(ip4);
		}
		else
		{
			ip_ring[end] = ip4;
			end = (++end)%100;	
		
		}
		pthread_mutex_unlock(&mutex);

	}
	void synchronizeIps(std::map<IP4, int> & ip4map)
	
	{  
		pthread_mutex_lock(&mutex);
		for (int n = begin; n != (end+1)%100; n = (n+1)%100)
		{
			int ipaddress_decimal;
			memcpy(&ipaddress_decimal, &ip_ring[n], sizeof(unsigned int));
			struct in_addr dst_addr;
			dst_addr.s_addr = __bswap_32(ipaddress_decimal);
			char *dot_dst_ip = inet_ntoa(dst_addr);
			ip4map[dot_dst_ip]++;
			begin = n;
		}
		pthread_mutex_unlock(&mutex);
	}
};

Open in new window

0
when i add an ip to my hashtable from main process before start fork or in the forked process child it count independantly num_entries then the normal process in the program.

How should i solve to not behave them independently ?

	void child(){
		int j = 0;
		for (; j < 5000; ++j)
		{
		    int num_entries = ip4map.size();
		    printf("%d   \n",num_entries);
			usleep(500000);
	            
		}
	}

Open in new window


	struct IP4
	{
	    unsigned char ip4[4];
	    IP4(const char * szip) 
	    {
	        const char * psz = &szip[0]; int n = 4;
	        *((unsigned int *)&ip4[0]) = 0;
	        do 
	        {
	            ip4[--n] = (unsigned char)atoi(psz);
	            psz = (const char*)strchr(psz, '.');
	        }
	        while (n > 0 && NULL != psz++);
	    }   
	    friend bool operator<(const IP4 & ip1, const IP4 & ip2) { return *((unsigned int *)&ip1.ip4[0]) < *((unsigned int *)&ip2.ip4[0]); }
	    operator std::string() 
	    { 
	        std::ostringstream oss; 
	        oss << (int)ip4[3] << '.' << (int)ip4[2] << '.' << (int)ip4[1] << '.' << (int)ip4[0]; 
	        return oss.str(); 
	    }
	};
	std::map<IP4, int> ip4map;

Open in new window

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.