Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 4th September 2008, 02:12
Owen_Townsend Owen_Townsend is offline
Junior Member
 
Join Date: Aug 2008
Location: Vancouver BC Canada
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default How to cast a char ptr to an array (to prevent warning, it does work)

/* testarray.c - to test compile warnings/errors */
/* "warning: passing arg1 from incompatible type" */
/* - by Owen Townsend, UV Software, Aug 25/2008 */
/* - original program was 20,000 lines (uvcopy.c) */
/* so I wrote this small test program to experiment*/

/* I was trying to pass a char ptr to a function which expects an array ptr*/
/* I was getting warning "passing arg1 from incompatible pointer type" */
/* note - program works OK, but I would like to eliminate the warning msg */
/* - I tried cast (char[][100]) but get "error: cast specifies array type" */

/* This test program written to investigate problem */
/* - here are warnings/errors from this test program */
/* 34: warning: passing arg1 of 'wordsep1' from incompatible pointer type*/
/* 36: error: cast specifies array type */
/* 38: error: cast specifies array type */
/* 40: warning: passing arg1 of 'wordsep1' from incompatible pointer type*/

char line[1000]; /* string to be split into words array */

char words[9][100]; /* words isolated from line */

char words2[1000]; /* words declared as an area vs array */

char *(words2p[9][100]); /* ptr to array of 100 elements */

/* declare prototype for wordsep1() function */
int wordsep1(char words[][100], char *input, int max, short bits);

int main (int argc, char *argv[])
{
wordsep1(words,line,9,0x03); /*32 <-- OK (no warning or error) */

wordsep1(words2,line,9,0x03); /*34 warning: arg1 incompatible type */

wordsep1((char[][100])words2,line,9,0x03); /*36 error: cast array type */

words2p = (char[][100])&(words2[0][0]); /*38 error: cast array type */

wordsep1(words2p,line,9,0x03); /*40 warning: arg1 incompatible type */

return(0);
}

/*-------------------------- wordsep1 ----------------------------*/
/* separate input string into array of words */

int wordsep1(char words[][100], char *input, int max, short bits)
{
return(1);
}
Reply With Quote
Sponsored Links
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Postfix delivery problem erebus Installation/Configuration 8 29th July 2014 21:17
Freebsd 6.1 support misterm Installation/Configuration 10 9th April 2009 10:29
This line keeps on showing up in my bind record yurtboy1 Installation/Configuration 5 30th November 2007 13:19
backup failure.... gilas Installation/Configuration 19 30th October 2007 13:08
log files, rotation and emailing them hairydog2 General 65 11th October 2006 14:18


All times are GMT +2. The time now is 02:55.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.