|
Probably a problem of structure packing / data alignment. With C/C++ structures and unions, member data are aligned by inserting padding bytes. How many bytes are inserted depends on the used compiler options where the default settings depend on the platform (CPU type and bit width).
When sending such structures via network to other systems, you must ensure that sender and receiver use the same packing / alignment. This is usally done by setting the alignment to one byte.
With Visual Studio use the #pragma pack[^] directive:
#pragma pack(push, 1)
union USendLive
{
struct SSend
{
float fTestValue1;
float fTestValue2;
char cChr;
} S;
unsigned char Buffer[LIVEUNISIZE];
} UNI;
#pragma pack(pop) Note that this might fail with existing (old) versions of your server and client. If so and you have to support old versions, you must check which alignment has been used and select that for packing.
BTW:
This forum is for managed C++ / CLI but your post would fit in the C++ / MFC forum.
|
|
|
|
|
I question how you are determining it is wrong. You code does not demonstrate that.
HOWEVER....
You are declaring a data entity on the stack. Then you are RETURNING part of that data entity from the method.
That is ALWAYS wrong.
And I suspect that is your problem.
The calling code also uses the stack. And will reuse exactly the same memory as where you are attempting to put a value if it wants to. For example if you are calling a method to 'print' the returned value in some way. Thus overwriting it. And that would cause a "junk" value either now or in the future.
|
|
|
|
|
i have tried it but it doen't work. It would be great if you could point out my mistake and better if correct it.
#include <stdio.h>
#include <conio.h>
int inc_order(int num[], int count, int i);
int compare(int hole, int value, int num[]);
int main(){
int num[50], n, count, j, i=0;
printf("Number of integers: \t");
scanf("%d", &count);
printf("\nEnter your integers: \n");
for(n=0; n<count; n++){
scanf("%d", &num[n]);
}
inc_order(num, count, i);
for(j=0; j<count; j++){
printf("%d", num[j]);
}
return 0;
}
int i=1;
void inc_order(int num[], int count, int i){
int value, hole;
if(i<count){
value = num[i];
hole = i;
}
compare(hole, value, num);
inc_order(num, count, i++);
}
int compare(int hole, int value, int num[]){
if(hole==0){
num[hole]=value;
return(num[hole]);
}
if(num[hole-1]>value){
num[hole] = num[hole-1];
hole--;
}
compare(hole, value, num);
}
modified 18-Nov-17 15:38pm.
|
|
|
|
|
That is not a proper task for recursion.
|
|
|
|
|
This is the code i came up with but it's too long, how to short it down.
#include <conio.h>
#include <stdio.h>
int main(){
int i=0, j, num[100], count=0, k, hcf[50], min;
printf("Enter your numbers: \n");
do{
scanf("%d", &num[i]);
i++;
count++;
}while(num[i-1]!=0);
min = num[0];
for(j=1; j<=count-2; j++){
if(min>num[j])
min = num[j];
}
int h=0, n[count-1];
for(j=0; j<=count-2; j++){
for(k=1; k<=min; k++){
if(num[j]%k==0){
hcf[h]=k;
h++;
}
}
n[j] = h;
}
int c=0, max[50], z;
for(i=0; i<n[0]; i++){
z=0;
for(j=n[0]; j<h; j++){
if(hcf[i]==hcf[j]){
z++;
}
}
if(z==(count-2)){
max[c]=hcf[i];
c++;
}
}
for(i=1; i<c; i++){
if(max[0]<max[i])
max[0]=max[i];
}
printf("\nHcf : %d\n", max[0]);
return 0;
}
<pre lang="c++"><pre lang="c++"><pre lang="c++"><pre lang="c++"><pre lang="c++"><pre lang="c++"><pre lang="c++">
|
|
|
|
|
You can do most of the work in a single loop.
|
|
|
|
|
can you tell where i can decrease the size of code or how it can be done in single loop ?
|
|
|
|
|
Yes, but this is your homework. Before you start coding try to write things out on paper and look at the best ways to get what you need. See how many things you can do in the first loop. For example, you can check each number to see if it is the smallest or largest as you read them in.
|
|
|
|
|
I am looking at some MSDN documentation and the "C++" code example are empty with the message
"No code example is currently available or this language may not be supported."
Is it because the feature is not available in C++ or that is is just not "documented with code examples"
The thing I am looking at is Enumerable::ToDictionary
see the MSDN documentation :
Enumerable.ToDictionary(TSource, TKey) Method (IEnumerable(TSource), Func(TSource, TKey)) (System.Linq)
There is not C++ example.
Is it possible to convert that code to C++ ?
Thanks.
I'd rather be phishing!
|
|
|
|
|
Maximilien wrote: Is it possible to convert that code to C++ ? Not easily as C++ has no simple IEnumerable class. However you may be able to adapt one of the other STL collection classes. See Standard C++ Library Reference[^].
|
|
|
|
|
Since Linq was designed as a C# language feature, many uses of it don't include a C++/CLI example in my experience. I have used it from C++/CLI however but it takes a bit of tinkering. Here's one example from a simple utility I had where I used ToList() which is probably similar to ToDictionary().
List<String^>^ files = Linq::Enumerable::ToList<String^>(Directory::EnumerateFiles(dataDir, "*.dat"));
int count = Linq::Enumerable::Count(files);
I've not yet encountered something managed which just could not be done from C++/CLI. But, the C# syntax is often more direct.
|
|
|
|
|
i've a code. the code cant be compile. what i can to do this problem. what the step would be i step?
|
|
|
|
|
Read the error message. It contains the source file name and line number where the error occured. If not, it is probably a linker error.
Try to understand the error message. Read the documentation for the error message. Search the net for the error message.
Compiler error: Inspect the reported line and the previous ones (some errors are sourced by invalid statements in previous lines but detected later).
If you have multiple error messages, start with the first (subsequent errors may be sourced by previous ones).
If you still not get it solved, ask here (or in other forums) providing the complete error message and related code. If necessary add additional information (e.g. about variables used by the code, used compiler, platform).
|
|
|
|
|
I m using VC++ VS2008 compact edition. I hv problem that
when I m using "
GetUsbDriveLetter(CString) at compiled time error occurred not defined because it is in winbase.h sdk function. And CE7 hv different sdk therefore it occurred. please suggest me how to get USB letter in CE7
YogeshJadhav
|
|
|
|
|
There is no GetUsbDriveLetter function in any Windows API (I don't know that function and a quick search did not found it too). Especially it can't be defined in winbase.h because that declares only plain Win32 functions which does not know the CString type.
Also, please don't post the same question at multiple places. I suggest that you delete the duplicate in the ATL / WTL / STL Discussion Boards[^]. Even this forum is not the correct one. The C / C++ / MFC board would have been a better choice.
|
|
|
|
|
sorry sir but how to delete it
|
|
|
|
|
It's too late now because there is a reply.
That is the problem with cross posts:
You have multiple threads on the same topic with replies from different users.
|
|
|
|
|
actual error is
Error 294 error C3861: 'GetLogicalDriveStrings': identifier not found
|
|
|
|
|
And I have already answered that question.
|
|
|
|
|
|
I don't know much about Windows CE but AFAIK that does not use drive letters. It mounts drives like Unix at the root folder. A quick search indicates that you can might use the StoreManager (FindFirstStore / FindNextStore ) to enumerate drives.
|
|
|
|
|
how to make a program in singly linked list that can divided two part,where the first linked list contain Element with an odd number element value and the second is even number.
thank you
|
|
|
|
|
|
thank you for your reply..
this is the code in klien.c
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
int main(int argc, char *argv[]){
List L = NULL;
Position P = NULL;
L = Construct(L);
P = Header(L);
int i, n, *element;
printf("Entri element: ");
scanf("%d", &n);
element = (int*)malloc(n*sizeof(int));
for(i =0; i<n; i++){
printf("Entri element[%d]: ", i);
scanf("%d", &element[i]);
Insert(element[i], L, P);
P = Advance(P);
}
printf("\n");
getLargestElement(L);
return 0;
}
this is the code in list.h
typedef int ElementType;
#ifndef _List_H
#define _List_H
struct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
List Construct(List L);
Position Header(List L);
void Insert(ElementType X, List L, Position P);
int IsLast(Position P, List L);
Position Advance(Position P);
Position getLargestElement(List L);
int IsEmpty(List L);
#endif
and the last in list.c
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
struct Node{
ElementType Element;
Position Next;
};
List Construct(List L){
L = malloc(sizeof(struct Node));
if(L==NULL)
printf("Memori Kosong dan Tidak Dapat Dialokasi");
L->Next = NULL;
return L;
}
Position Header(List L){
return L;
}
void Insert(ElementType X, List L, Position P){
Position TmpCell = NULL;
TmpCell = malloc(sizeof(struct Node));
if(TmpCell == NULL) printf("Memori Kosong dan Tidak Dapat Dialokasi");
TmpCell->Element = X;
TmpCell->Next = P->Next;
P->Next = TmpCell;
}
int IsLast(Position P, List L){
return P->Next == NULL;
}
Position Advance(Position P){
return P->Next;
}
int IsEmpty(List L){
return L->Next == NULL;
}
Position getLargestElement (List L){
ElementType Largest;
Position P;
if(!IsEmpty(L)){
P = L->Next;
Largest = P->Element;
while(!IsLast(P, L)){
P = P->Next;
if(P->Element > Largest){
Largest = P->Element;
}
}
printf("element terbesar adalah: %d\n",Largest);
}
else{
printf("tidak ada ");
}
return 0;
}
and my problem is i dont know how to make a splitlist function in my email before..
thank you
|
|
|
|
|
You just need two new lists, one for odd numbers and one for even. Then for each value in the original list you add it to the appropriate new list.
|
|
|
|