UVM indexing into array by get_type_name - verilog

Is this possible? Get_type_name is a string. Can't I have an int array and use the name to index in? I get index expression type of illegal.
Obj n1;
int number[100];
n1 = new();
number[n1.get_type_name] = 1;

Long day. Should have declared int number[string]

Related

VC++ How to SUM two biginteger numbers

Say I have
static System::Numerics::BigInteger MinimoNumero; int16_t Uno = 1;
static System::Numerics::BigInteger MaximoNumero;
static const std::string MaximoNumeroString = "91389681247993671255432112333333333333333333333333333333333333333333333333333333333333333333333333333333";
MaximoNumero = System::Numerics::BigInteger::Parse(marshal_as<String^>(MaximoNumeroString));
MinimoNumero = System::Numerics::BigInteger::Parse("1");
How can I SUM 1 to MaximoNumero so I want a result as BigInteger as 91389681247993671255432112333333333333333333333333333333333333333333333333333333333333333333333333333334
If I use
System::Numerics::BigInteger NUM = MinimoNumero + MaximoNumero;
then I got error "more than one operator "+" matches these operands.."
You can't (generally) use the plain arithmetic operators on the BigInteger type. Instead, call the relevant member function(s) of the BigInteger type – in this case, the Add function:
System::Numerics::BigInteger NUM = System::Numerics::BigInteger::Add(MinimoNumero, MaximoNumero);

garbage in loop for no reason

i wrote a function that receives a string as a char array and converts it to an int:
int makeNumFromString(char Str[])
{
int num = 0, len = 0;
int p;
len = strlen(Str);
for (p = 0; p<len; p++)
{
num = num * 10 + (Str[p] - 48);
}
return num;
}
the problem is that no matter how long the string i input is, when "p" gets to 10 the value of "num" turns to garbage!!!
i tried debbuging and checking the function outside of the larger code but no success.
what could be the problem and how can i fix it?
THANKS
Perhaps your int can only store 32 bits, so the number cannot be higher than 2,147,483,647.
Try using a type for num with more storage, like long.

Comparing a string in a struct with a string in an array

I have an array of structs, one of the elements in the struct is a string, and i need to compare those strings with other strings in an array of 12 strings. strcmp does not seem to work for me. I know i need to make seperate function to compare the the strings and return the value as a bool, but cant figure out how to make the compare function work.
The struct
typedef struct{
char *hometeam[Max_number_of_chars], *awayteam[Max_number_of_chars];
int playround, date_day, date_month, date_year,
time_hour, time_minute, home_score, away_score, crowd_thousand,
crowd_hundred;
} match;
The array of strings
char *teams[Number_of_teams] = {"AGF","AAB","SDR","RFC",
"EFB","BIF","SIF","OB",
"FCK","FCM", "ACH","FCN"};
the line where i need the compare_function
if(compare_names(all_games[i].hometeam, teams[j])==0) {//crazy stuff}
EDIT: What i need help with is making function that compares the string value from *teams[j] with the string value from all_games[i].hometeam. But i dont know how to pass the specific part of the struct all_games[i].hometeam to the compare_function, where i want it to be a char string.
// Assuming char *teams[Number_of_teams] is globally defined.
int find_match(struct match)
{
for(i=0; i < Number_of_teams; i++){
if(strcmpi(match.hometeam, teams[i]) == 0){
return i;
}
}
return -1;
}
The logical flow of what you want to do isn't clear, but you can try something like above.

How to count two characters in a string?

There are three parameters (String s, char c, char d)
How do I define a method so that it returns as an int, the number of times the char c occurs in the String s added to the number of times the char d occurs in the String s?
Depending on the language, there could already be an existing function that does this for you.
Otherwise, you'd need to treat the string like an array (if the language does that, then great. If it doesn't, then you need to cast it into an array), run a loop and use a counter. If you want to look for specific characters, you can pass that in a function along with the string/array).
Example (this is just psudo-code, since I don't know what language you're using):
function countCharsInString(string s, char c1, char c2)
{
int count = 0;
for(i = 0; i < s.Length; i++)
{
if(s[i] == c1 || s[i] == c2)
{
count++;
}
}
return count;
}

Binary search for specific value in array of structs

I wrote this function that uses a binary search to look for a specific value in an array of structs. Why doesn't it compile?
I'm getting this error:
prog.c:224: error: subscripted value is neither array nor pointer
prog.c:226: error: subscripted value is neither array nor pointer
This is the function:
int FieldSearch(Field *pArr, int size, int val)
{
int low=0,high=size-1, middle;
while (low <= high)
{
middle = (low + high)/2;
if (val == pArr->Id[middle])
return middle;
else if (val < pArr->Id[middle])
high = middle -1;
else
low = middle +1;
}
return NOT_FOUND;
}
This is the field struct:
typedef struct field
{
char Id;
Coordinates location;
int area;
int price;
} Field;
Maybe the prototype is wrong...
Your problem is this statement:
pArr->Id[middle]
It looks like, but I don't have nearly enough info, that your member Id is not a pointer or an array, but merely a variable. So you cannot access it with an operator[]. You should show us what this Field object looks like.
I'm guessing you should do something like this
(pArr + middle)->Id so this will access the element of the Field array you passed into your function. Then you do have to pass in an actual array of Field structures, for this to work.
If you want to search the "array" pArr, you need to put the brackets directly behind the identitifier. This should work:
pArr[middle].Id

Resources