|
ok, you have any suggested references for C tutorials? e-books, web, or anything...
|
|
|
|
|
Why do you need a tutorial? Read the latest K & R.
|
|
|
|
|
Try this video series: https://youtu.be/F3ntGDm6hOs
This is a "pre-introduction" series of 5 videos, to the Handmade Hero video series. HH is an ongoing series and may/may not be valuable to you, but the prelim is a good, fast intro that explains a bunch of concepts on Windows.
|
|
|
|
|
You got caught by the spam filter that put your message in moderation. Next time be a bit patient please instead of posting again.
I have let both messages through and deleted the other one.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
ic... maybe i was thought it got an error while posting...
|
|
|
|
|
I was trying to use win API
GetComputerObjectNameW as below but I am getting error. Can someone help me.
#include <iostream>
#include <atlbase.h>
#include <secext.h>
typedef enum {
NameUnknown,
NameFullyQualifiedDN,
NameSamCompatible,
NameDisplay,
NameUniqueId,
NameCanonical,
NameUserPrincipal,
NameCanonicalEx,
NameServicePrincipal,
NameDnsDomain,
NameGivenName,
NameSurname
} EXTENDED_NAME_FORMAT, *PEXTENDED_NAME_FORMAT;
int main()
{
EXTENDED_NAME_FORMAT enf = NameFullyQualifiedDN;
LPWSTR pwszComputerName;
DWORD dwLen;
dwLen = 0;
GetComputerObjectNameW(enf, NULL, &dwLen);
pwszComputerName = new WCHAR[dwLen + 1];
if(NULL == pwszComputerName)
{
return 0;
}
if(!GetComputerObjectNameW(NameSamCompatible, pwszComputerName, &dwLen))
{
delete pwszComputerName;
return 0;
}
sbstrTrustee = pwszComputerName;
wprintf(L"GetComputerObjectName: %s\n", pwszComputerName);
delete pwszComputerName;
}
Some of Error message is as below.
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): error C2146: syntax error: missing ';' before identifier 'GetUserNameExA'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(121): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2086: 'BOOLEAN SEC_ENTRY': redefinition
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(117): note: see declaration of 'SEC_ENTRY'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(126): error C2146: syntax error: missing ';' before identifier 'GetUserNameExW'
C:\Program Files (x86)\Windows Kits\8.1\include\\shared\secext.h(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
|
|
|
|
|
Why do you redefine the EXTENDED_NAME_FORMAT enumeration?
|
|
|
|
|
I first try without defining enum after that try with enum. In both case I am getting compilation error.
|
|
|
|
|
Add these definition:
#define _WIN32_WINNT 0x0500
#define SECURITY_WIN32
Remove the redefinition of enum.
Define the sbstrTrustee variable.
// edited: also don't forget to include the Secur32.lib library.
|
|
|
|
|
Hi Victor,
I have modified program according to your suggestion but I am not getting expected result. I want to use NameFullyQualifiedDN enum value and get the fully qualified distinguished name (for example, CN=Jeff Smith,OU=Users,DC=Engineering,DC=Microsoft,DC=Com).
Regards,
Rajnesh
|
|
|
|
|
Sorry, I don't know what is wrong/correct in your test.
I've just tested your code and got the result in the form:
[my_domain_name].[my_computer_name]$
wich is in my case 100% correct.
|
|
|
|
|
Hi Victor,
There was configuration issue with my windows laptop, so I was facing issue. Thanks for your feedback.
|
|
|
|
|
Good morning,
You are including the wrong header. Remove secext.h and add:
#include <Security.h> The error message is telling you that it doesn't know the definition of SEC_ENTRY .
|
|
|
|
|
Hi All,
//program to place even numbers in one array and odd numbers in another array
PFA code.
#include<stdio.h>
void main()
{
int array[20],array1[20],array2[20],i,n,j;
printf("enter how many array elements\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&array[i]);
="" }
="" ***************even="" odd="" in="" array="" elements***************=""
for(i="0;i<n;i++)
{
" if(array[i]%2="=0)
"
="" {
="" array1[i]="array[i];//even" array
="" }
="" else
="" array2[i]="array[i];//odd"
}
="" ******************printing="" elements)*********="" for(i="0;i<n;i++)
" printf("="" even="" is:%d\n",array1[i]);="" printing="" array
}
printf("\n");
for(j="0;j<n;j++)
{
" is="" :%d\n",array2[j]);="" array
}
}
="" output="" what="" i="" got:
enter="" how="" many="" elements
5
1
2
3
4
5
="" is:1970776="" to="" avoid="" this="" is:2
="" is:-1968723210="" my="" output
="" is:4
="" is:4202864="" this
="" :1
="" ="" am="" getting="" :3
="" :32762="" why="" addresss="" junl="" value
="" :5
--------------------------------
process="" exited="" after="" 7.24="" seconds="" with="" return="" value="" 5
press="" any="" key="" continue="" .="" .<="" pre="">
modified 18-Feb-21 0:51am.
|
|
|
|
|
You are putting holes in your arrays of even and odd elements. In order to avoid that, you need to maintain two separate variables to keep track of how many even and odd items have been added so far. Try
#include <stdio.h>
#define SIZE 20
int main()
{
int items, odd_items, even_items;
int array[SIZE], odd[SIZE], even[SIZE];
printf("enter how many array elements\n");
scanf("%d",&items);
odd_items = even_items = 0;
for (int n=0; n<items; ++n)
{
printf("enter item %d:\n", n);
scanf("%d", &array[n]);
if ( (array[n] % 2) == 0)
{
even[even_items] = array[n];
++even_items;
}
else
{
odd[odd_items] = array[n];
++odd_items;
}
}
printf("array items\n");
for (int n=0; n<items; ++n)
printf("%d ", array[n]);
printf("\n");
printf("even array items\n");
for (int n=0; n<even_items; ++n)
printf("%d ", even[n]);
printf("\n");
printf("odd array items\n");
for (int n=0; n<odd_items; ++n)
printf("%d ", odd[n]);
printf("\n");
return 0;
}
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
5, but you should get 10 for looking at code formatted this way.
|
|
|
|
|
Thank you.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Hi,
#include<stdio.h>
int main()
{
char str[20] = "Hello";
char *const p=str;
*p='M';
printf("%s\n", str);
return 0;
}
output:
Mello
As per my knowledge when we use const then we can't change a char in t then how output is Mello instead of Hello.
|
|
|
|
|
You need to read the declaration right to left:
char *const p=str;
| | | |
| | | +- the variable p
| | +----- is a constant
| +---------pointer
+------------to a character
So const here applies to the pointer p and not to the data that it is pointing to. That would be:
const char* p=str;
|
|
|
|
|
Hi Richard,
Thank you for your reply. I understood the concept clearly.
Best Regards
Niharika
|
|
|
|
|
const applies to what's on its immediate left: a pointer (* ) or a type (char and many others, even ones that you've defined). If there's nothing on its left--that is, when it appears first--const applies to what's on its immediate right.
modified 15-Feb-21 7:23am.
|
|
|
|
|
Hi Greg,
Thank you for your immediate response. I understood the point clearly.
Regarda,
Niharika
|
|
|
|
|
Hi All,
I am learning callbacks in c.I found an example in callback but could not understand .Can some one please explain me how the flow of execution happens and brief explaination of program.
PFA code what I found.
<pre>* callback.c */
#include<stdio.h>
#include"reg_callback.h"
/* callback function definition goes here */
void my_callback(void)
{
printf("inside my_callback\n");
}
int main(void)
{
/* initialize function pointer to
my_callback */
callback ptr_my_callback=my_callback;
printf("This is a program demonstrating function callback\n");
/* register our callback function */
register_callback(ptr_my_callback);
printf("back inside main program\n");
return 0;
}
/* reg_callback.h */
typedef void (*callback)(void);
void register_callback(callback ptr_reg_callback);
/* reg_callback.c */
#include<stdio.h>
#include"reg_callback.h"
/* registration goes here */
void register_callback(callback ptr_reg_callback)
{
printf("inside register_callback\n");
/* calling our callback function my_callback */
(*ptr_reg_callback)();
}
|
|
|
|
|
void my_callback(void)...
int main(void)
{
callback ptr_my_callback = my_callback;
register_callback(ptr_my_callback);
}
typedef void (*callback)(void);
void register_callback(callback ptr_reg_callback)
{
(*ptr_reg_callback)();
}
The printf s are just there so that you can observe the flow of execution.
modified 10-Feb-21 11:52am.
|
|
|
|
|
You might already be familiar with callbacks and not realize it. If you've ever used qsort() or bsearch() , or another library function that takes a function pointer as an argument to help it do its work, you have already used callbacks!
For example the signature for qsort is
void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); and might be used like this
struct foo {
char key[10];
int id;
};
int cmpfoo_bykey(const void *vp1, const void *vp2)
{
const struct foo *foo1 = vp1;
const struct foo *foo2 = vp2;
return strcmp(foo1->key, foo2->key);
}
int cmpfoo_byid(const void *vp1, const void *vp2)
{
const struct foo *foo1 = vp1;
const struct foo *foo2 = vp2;
return foo1->id - foo2->id;
}
int main()
{
struct foo my_data[100];
qsort(my_data, 100, sizeof(struct foo), cmpfoo_bykey);
qsort(my_data, 100, sizeof(struct foo), cmpfoo_byid);
return 0;
}
In the above example qsort() knows how to sort an array of items in a generic way, but not how to compare items. It gets around this limitation by using a callback function, that the programmer provides, that does know how to compare items in the array. So, whenever qsort() needs to know how two items in the array compare to each other, it calls back to the code provided by the programmer to determine how the two items compare to each other.
Keep Calm and Carry On
|
|
|
|
|