Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Re: easy parsing problem in C for beginner



Tip: Looking for answers? Try searching our database.



You are accessing this site in a read-only mode. For full access to all member benefits, including message posting, please login or register. Registration is completely free, simple, and takes only a few seconds.

Login | Free MacKB.com registration | Whole discussion thread

The message you are replying to and its parents are listed in the reverse order with the most recent posts first. This might not be the whole discussion thread. To read all the messages in this thread please click here.

Re: easy parsing problem in C for beginner

GreyCloud08 Feb 2010 02:52
> Is there a way to capture the ascii values of these printf statments?
>
[quoted text clipped - 5 lines]
> If I could capture the value 97 and the recovert it back to an 'A',
> that would go a long way to solving my problem.

Just give the numeric variable a (char) cast and see how it turns out
for you in a printf statement.
Of course if you want to make it an uppercase 'A' there are two
approaches to it.  1) use the toupper function that is in the string
lib.  2) subtract 32 from 97 and then cast it as a char.
I'm sure there are other means as well.
But it would help if I knew what the PA_variable definition is.

John Mosby08 Feb 2010 02:40
Is there a way to capture the ascii values of these printf statments?

char mychar = 'A';

printf("char: %c\n", mychar); // Prints the character 'A'
printf("ASCII: %d\n", mychar); // Prints the number 65

If I could capture the value 97 and the recovert it back to an 'A',
that would go a long way to solving my problem.

GreyCloud07 Feb 2010 21:35
> I am having trouble as a C beginning trying to compile the code below
> using XCode.  I am new to C and have always programmed in pascal in
[quoted text clipped - 79 lines]
> //ERROR BELOW (error before "int")
>         Day_Difficulty_AsciiValue = (int)(DayArray[counter2]);  // function to

In C for an int cast it should look like (int).

> convert a char in array to ascii value
>         if (Day_Difficulty_AsciiValue>=65) // is character a letter
[quoted text clipped - 15 lines]
> //ERROR BELOW  (error before "char") (error before '+' token)
>             slot_char = (char)(slot_number+48+7);

Always put a cast inside parentheses.
>         else  // this will be a number
>             slot_char = (char)(slot_number+48);

I've put in the required parens.

> //ERROR BELOW    (subscripted value is neither array nor pointer)
>         FinishedArray[counter2] = slot_char;  // store the character back

I'll need the actual line definition of PA_Variable to figure that one out.

> into the original array to be passed to 4D
>     }
[quoted text clipped - 6 lines]
>     PA_ReturnString( params, returnValue );
> }

John Mosby07 Feb 2010 14:17
I am having trouble as a C beginning trying to compile the code below
using XCode.  I am new to C and have always programmed in pascal in
the past. This is to be a plugin for 4th Dimension.  Most of the hooks
were generated with "4D Plugin Wizard".  It generates the C code for
the plugin to be used by XCode.  I think most of my errors are simple
declaration problems or problems with the C language.  I am getting
the following errors:

error: parse error before "int"
error: parse error before "char"
error: parse error before '+' token
error: subscripted value is neither array nor pointer

The code follows:

/*
--------------------------------------------------------------------------------
#
#    4DPlugin.c
#    source generated by 4D Plugin Wizard
#    Project : new Project
#    author : subaru
#    1/29/10
#
# This plugin should recieve two variable from the main 4D program.
#
# The first variable from 4D --------------
# One will be an array of length 54 composed of
# characters (0-9 and A-Z).  Each element represents a schedule day.
Each character in the element represents a
# 10 minute block of time in the schedule.  When the character is 0
(zero) there is nothing scheduled for that time.
# The difficulty of the the 10 minute time block increases as the
ascii value of the character that represents it
# increases in value from 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,..... etc.
#
# The second variable from 4D --------------
# This variable will be an integer value that represents the
difficulty of the new appointment.
# This value should be subtracted from the ascii value of the
character that represents each 10 minute
# time block.  The harder the new appointment the smaller the value
of the variable for the difficulty.
#
--------------------------------------------------------------------------------
*/

// -------------------------------- schedule Plugin
-------------------------------

void s_Convert_Array( PA_PluginParameters params )
{

    PA_Variable DayArray; //an array of characters of length 54 from 4d
    short Difficulty;  //an interger denoting difficulty of an
appointment
    PA_Variable FinishedArray;  // completed array returned to 4D
    char returnValue[256];

    DayArray = PA_GetVariableParameter( params, 1 );
    Difficulty = PA_GetShortParameter( params, 2 );

    // --- write the code of s_Convert_Array here...

{
int counter = 0;
int array_size = sizeof(DayArray);
int Day_Difficulty_AsciiValue; //used to hold one character
int slot_number;
char slot_char;

while (counter < array_size)  //array_size should be the number of
elements of array DayArray
{
    counter++;

    int counter2 = 0;
    while (counter2 < 55)  //stepping through each character of DayArray
    {
        counter2++;

//ERROR BELOW (error before "int")
        Day_Difficulty_AsciiValue =int(DayArray[counter2]);  // function to
convert a char in array to ascii value
        if (Day_Difficulty_AsciiValue>=65) // is character a letter
            slot_number = Day_Difficulty_AsciiValue-7-48;
        else //character is a number
            slot_number = Day_Difficulty_AsciiValue-48;

        slot_number = slot_number - Day_Difficulty_AsciiValue;

        if(slot_number<0)
            slot_number = 0;

// convert the number to the characters 0-1,A-Z
// 48 is the number of ascii values before the numbers begin
// 7 is the numbere of unused ascii values between the numbers and
capital letters

        if(slot_number>=10) //number will be converted to a character
//ERROR BELOW  (error before "char") (error before '+' token)
            slot_char = char(slot_number+48+7);
        else  // this will be a number
            slot_char = char(slot_number+48);

//ERROR BELOW    (subscripted value is neither array nor pointer)
        FinishedArray[counter2] = slot_char;  // store the character back
into the original array to be passed to 4D
    }

}

}

    PA_SetVariableParameter( params, 3, FinishedArray, 1 );
    PA_ReturnString( params, returnValue );
}

Quick links:

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage




©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.