473,322 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

access violation error while trying to memset() the typedef element of the struct

1
Hi All,
I have a typedef element defined inside the struct which i am trying to assign value using the memset and strcpy function.I am able to compile but while running it give me access violation error.Here is my code
Expand|Select|Wrap|Line Numbers
  1. **********
  2. #ifndef DEFINE_SAMPLETYPES
  3. #define DEFINE_SAMPLETYPES
  4.  
  5. typedef char MANUFACTURER_PART_NUMBER[48];
  6.  
  7. #endif
  8.  
  9. *******************************************
  10. #ifndef DEFINE_SAMPLE_WKSP
  11. #define DEFINE_SAMPLE_WKSP
  12. #include "SAMPLETYPEDEF.H"
  13. typedef struct{
  14.  
  15. MANUFACTURER_PART_NUMBER manufacturer_part_number;
  16.  
  17. }IN_SAMPLE_WKSP;
  18.  
  19. #endif
  20. ****************************
  21. #include "SAMPLE_WKSP.H"
  22.  
  23.  IN_SAMPLE_WKSP *po;
  24.  
  25.  main()
  26.  {
  27.  
  28. memset(&(po)->manufacturer_part_number,' ',48);
  29. strcpy(&(po)->manufacturer_part_number,"hello");
  30.  
  31. }
  32.  
can you guide me where i am doing mistake.Is this correct way of accessing the typedef element in a struct.

Thanks for the Help
Nov 4 '09 #1
3 3864
ashitpro
542 Expert 512MB
@bamsi
According to my knowledge,
you ll have to first allocate the memory to IN_SAMPLE_WKSP *po;
then do your memset and other logic.
Nov 4 '09 #2
donbock
2,426 Expert 2GB
Another way to put it is that po is an uninitialized pointer. You need to initialize it to point at an IN_SAMPLE_WKSP.
Nov 4 '09 #3
Banfa
9,065 Expert Mod 8TB
@bamsi
Even if you initialise po correctly these lines are not correct the & is unnecessary. This effects the type, rather than the value, of the pointer but most good compilers would issue a warning for this.
Nov 4 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: muser | last post by:
In the code I supplied before this one, the cause of the problem is an access violation error. When I run the debugger it skips into what I can only assume is the compilers version of my code. And...
3
by: Kyle Teague | last post by:
I have a list of pointers to structs as a private member of a class. If I call begin() in the same function as I added the data then no access violation occurs. However, if I try to call begin() in...
13
by: JasBascom | last post by:
int main() { char record_typec = 'c'; record_typec = toupper(record_typec); * rec->Newcrecord.record_type = record_typec; etc etc \*********************************************\
3
by: paulrc_25 | last post by:
I'm working with C++ Builder 5.0 Enterprise Edition, and I got this message: Project CntSch.exe raised exception class EAccessViolation with message 'Access violation at address 40004B66 in...
3
by: Alfonso Morra | last post by:
I have some code that I am porting over from C. It is full of static functions and global variables. I have got around this by wrapping most of the code in a singleton object. However, I am...
22
by: srivatsan_b | last post by:
Hi, Can somebody explain whether an explicit typecast is mandatory while calling memset function for a structure? like in the following code snapshot..... struct some_structure x;...
21
by: jacob navia | last post by:
Many compilers check printf for errors, lcc-win32 too. But there are other functions that would be worth to check, specially memset. Memset is used mainly to clear a memory zone, receiving a...
5
by: pmm | last post by:
hi I am a beginner in network programming I am trying out a UDP packet transfer between a windows machine and a linux I created a structure on both sides (ie on linux and on windows) and I sent...
5
by: Mahendra Kumar Kutare | last post by:
I am trying to implement a webserver with boss-worker model thread pool implementation - I have a header declaration threadpool.h as - typedef struct threadpool_work { void (*routine) ();...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.