473,385 Members | 1,546 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,385 software developers and data experts.

VS2010 giving me Debug Assertion Failure in C++

29
Hello, I am having a problem running my program with libcurl,

What puzzles me is that this program works on Visual Studio 2010 on my computer running Windows XP, however when I try to run the same program on my laptop which runs Windows 7, it gives me the following error message:

Debug Assertion Failed!

Program: C:\Project\libcurl\VisualStudio\project1\Debug\pro ject1.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\fwrite.c
Line: 77

Expression: (stream != NULL)

if you need to see my code, here it is:

main.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "txtfiles.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     txtfiles gs;
  9.     gs.organize();
  10.  
  11.     return 0;
  12. }
  13.  
dateclass.h
Expand|Select|Wrap|Line Numbers
  1. #include "numdate.h"
  2. #include "numvalue.h"
  3.  
  4. using namespace std;
  5.  
  6. class dateclass
  7. {
  8. private:
  9.     ushort day;
  10.     ushort newday;
  11.     ushort month;
  12.     ushort year;
  13.     string curdate;
  14.     string srchdate;
  15.     string weekday;
  16.     string datestring;
  17.     time_t rawtime;
  18. public:
  19.  
  20.     void reset(){
  21.         time(&rawtime);
  22.         datestring = ctime(&rawtime);
  23.         curdate.clear();
  24.         datestring.clear();
  25.     }
  26.  
  27.     dateclass() //date constructor 
  28.     {
  29.         time(&rawtime);
  30.         datestring = ctime(&rawtime);
  31.  
  32.         curdate = datestring;
  33.         curdate.erase(0,4); //remove day prefix
  34.         curdate.erase(7,9); //remove time
  35.         curdate.insert(6, ",", 1); //insert comma
  36.  
  37.         numvalue current(curdate);
  38.  
  39.         month = current.getmonth();
  40.         day = current.getday();
  41.         year = current.getyear();
  42.  
  43.         weekday = datestring.substr(0,3);
  44.     };
  45.  
  46.     const string& getcurdate()
  47.     {
  48.         srchdate = curdate;
  49.         if (day < 10) //change "0x" to "x" in date
  50.             srchdate = curdate.erase(4,1);
  51.         return srchdate;
  52.     };
  53.  
  54.     string decrement(ushort decrement)
  55.     {        
  56.         numdate numeric (month, day, year, weekday);
  57.         numeric.decrement(decrement);
  58.  
  59.         srchdate = numeric.revert();
  60.         numvalue search(srchdate);
  61.         newday = search.getday();
  62.  
  63.         if (newday < 10)
  64.             srchdate = srchdate.erase(4,1);
  65.  
  66.         return srchdate;
  67.     };
  68. };
  69.  
exclusion.h
Expand|Select|Wrap|Line Numbers
  1. #include <time.h>
  2. #include <string>
  3.  
  4. typedef unsigned short ushort;
  5. using namespace std;
  6.  
  7. class exclusion
  8. {
  9. private:
  10.     string weekday;
  11.     ushort num;
  12.     ushort value;
  13.  
  14. public:
  15.     exclusion(string weekday)
  16.     {
  17.         if(weekday == "Sat") num = 0;
  18.         else if(weekday == "Sun") num = 1;
  19.         else if(weekday == "Mon") num = 2;
  20.         else if(weekday == "Tue") num = 3;
  21.         else if(weekday == "Wed") num = 4;
  22.         else if(weekday == "Thu") num = 5;
  23.         else num = 6;
  24.     };
  25.  
  26.     ushort decrement(ushort countdown)
  27.     {
  28.         countdown++;
  29.         value = countdown;
  30.  
  31.         if (num <= 2)
  32.         {
  33.             value += num;
  34.             value += 2 * ((countdown - 1)/ 5);
  35.             return value;
  36.         } else {
  37.             if (countdown > num - 2)
  38.             {
  39.                 value += 2;
  40.                 value += 2 * ((countdown - num + 1) / 5);
  41.                 return value;
  42.             } else {
  43.                 value = countdown;
  44.                 return value;
  45.             }
  46.         }
  47.     };
  48. };
  49.  
numdate.h
Expand|Select|Wrap|Line Numbers
  1. #include "exclusion.h"
  2.  
  3. using namespace std;
  4. const ushort Feb = 31;
  5.  
  6. enum holidays { NewYear = 1, MartinLuther = 18, Washington = 46, GoodFriday = 92, MemorialDay = 151,\
  7.     IndependenceDay = 187, LaborDay = 249, ThanksgivingDay = 329, Christmas = 358 };
  8.  
  9. class numdate
  10. {
  11. private:
  12.     ushort reduce;
  13.     ushort m_month;
  14.     ushort d_day;
  15.     ushort y_year;
  16.     string w_weekday;
  17.     ushort t_month;
  18.     ushort t_day;
  19.     ushort t_year;
  20.  
  21.     int raw;
  22.     ushort num_days;
  23.  
  24.     ushort Mar;
  25.     ushort Apr;
  26.     ushort May;
  27.     ushort Jun;
  28.     ushort Jul;
  29.     ushort Aug;
  30.     ushort Sep;
  31.     ushort Oct;
  32.     ushort Nov;
  33.     ushort Dec;
  34. public:
  35.     numdate(int month, int day, int year, string weekday) : m_month(month), d_day(day), y_year(year), w_weekday(weekday)
  36.     {
  37.  
  38.     }
  39.  
  40.     ushort ret_month() {return m_month;};
  41.     ushort ret_day() {return d_day;};
  42.     ushort ret_year() {return y_year;};
  43.  
  44.     void decrement(ushort decrement)
  45.     {
  46.         if (y_year % 4 == 0)
  47.             {Mar = 60; Apr = 91; May = 121; Jun = 152; Jul = 182;
  48.             Aug = 213; Sep = 244; Oct = 274; Nov = 305; Dec = 335;}
  49.         else
  50.             {Mar = 59; Apr = 90; May = 120; Jun = 151; Jul = 181;
  51.             Aug = 212; Sep = 243; Oct = 273; Nov = 304; Dec = 334;}
  52.  
  53.         switch(m_month)
  54.         {
  55.         case 1: break;
  56.         case 2:    num_days = d_day + Feb; break;
  57.         case 3: num_days = d_day + Mar; break;
  58.         case 4: num_days = d_day + Apr; break;
  59.         case 5: num_days = d_day + May; break;
  60.         case 6: num_days = d_day + Jun; break;
  61.         case 7: num_days = d_day + Jul; break;
  62.         case 8: num_days = d_day + Aug; break;
  63.         case 9: num_days = d_day + Sep; break;
  64.         case 10: num_days = d_day + Oct; break;
  65.         case 11: num_days = d_day + Nov; break;
  66.         case 12: num_days = d_day + Dec; break;
  67.         }
  68.  
  69.         t_year = y_year;
  70.  
  71.         exclusion decrease(w_weekday);
  72.         reduce = decrease.decrement(decrement);
  73.  
  74.         while (num_days < reduce)
  75.         {
  76.             t_year = t_year - 1;
  77.             if (t_year % 4 == 0) {num_days += 366;}
  78.             else {num_days += 365;}
  79.         }
  80.  
  81.         raw = num_days - reduce;
  82.  
  83.         if (raw <= NewYear && num_days >= NewYear)
  84.             decrement++;
  85.         if (raw <= MartinLuther && num_days >= MartinLuther)
  86.             decrement++;
  87.         if (raw <= Washington && num_days >= Washington)
  88.             decrement++;
  89.         if (raw <= GoodFriday && num_days >= GoodFriday)
  90.             decrement++;
  91.         if (raw <= MemorialDay && num_days >= MemorialDay)
  92.             decrement++;
  93.         if (raw <= IndependenceDay && num_days > IndependenceDay)
  94.             decrement++;
  95.         if (raw <= LaborDay && num_days >= LaborDay)
  96.             decrement++;
  97.         if (raw <= ThanksgivingDay && num_days >= ThanksgivingDay)
  98.             decrement++;
  99.         if (raw <= Christmas && num_days >= Christmas)
  100.             decrement++;
  101.  
  102.         reduce = decrease.decrement(decrement);
  103.         t_day = num_days - reduce;
  104.  
  105.         if (t_day <= 0)
  106.         {
  107.             t_year = t_year - 1;
  108.             if (t_year % 4 == 0) {t_day += 366;}
  109.             else {t_day += 365;}
  110.         }
  111.  
  112.         if (t_day > Dec) {t_day = t_day - Dec; t_month = 12;}
  113.         else if (t_day > Nov) {t_day = t_day - Nov; t_month = 11;}
  114.         else if (t_day > Oct) {t_day = t_day - Oct; t_month = 10;}
  115.         else if (t_day > Sep) {t_day = t_day - Sep; t_month = 9;}
  116.         else if (t_day > Aug) {t_day = t_day - Aug; t_month = 8;}
  117.         else if (t_day > Jul) {t_day = t_day - Jul; t_month = 7;}
  118.         else if (t_day > Jun) {t_day = t_day - Jun; t_month = 6;}
  119.         else if (t_day > May) {t_day = t_day - May; t_month = 5;}
  120.         else if (t_day > Apr) {t_day = t_day - Apr; t_month = 4;}
  121.         else if (t_day > Mar) {t_day = t_day - Mar; t_month = 3;}
  122.         else if (t_day > Feb) {t_day = t_day - Feb; t_month = 2;}
  123.         else {t_month = 1;}
  124.  
  125.     };
  126.  
  127.     string revert()
  128.     {
  129.         string vdate;
  130.  
  131.         switch (t_month)
  132.         {
  133.         case 1: vdate += "Jan "; break;
  134.         case 2: vdate += "Feb "; break;
  135.         case 3: vdate += "Mar "; break;
  136.         case 4: vdate += "Apr "; break;
  137.         case 5: vdate += "May "; break;
  138.         case 6: vdate += "Jun "; break;
  139.         case 7: vdate += "Jul "; break;
  140.         case 8: vdate += "Aug "; break;
  141.         case 9: vdate += "Sep "; break;
  142.         case 10: vdate += "Oct "; break;
  143.         case 11: vdate += "Nov "; break;
  144.         case 12: vdate += "Dec "; break;
  145.         }
  146.  
  147.         vdate += ((char) ((t_day / 10) + 48));
  148.         vdate += ((char) ((t_day % 10) + 48));
  149.  
  150.         vdate += ", ";
  151.  
  152.         vdate += ((char) ((t_year / 1000) + 48));
  153.         vdate += ((char) (((t_year % 1000) / 100) + 48));
  154.         vdate += ((char) ((((t_year % 1000) % 100) / 10) + 48));
  155.         vdate += ((char) ((((t_year % 1000) % 100) % 10) + 48));
  156.  
  157.         return vdate;
  158.     };
  159. };
  160.  
numvalue.h
Expand|Select|Wrap|Line Numbers
  1. #include <string>
  2.  
  3. typedef unsigned short ushort;
  4. using namespace std;
  5.  
  6. class numvalue
  7. {
  8. private:
  9.     ushort day;
  10.     ushort month;
  11.     ushort year;
  12.     char number;
  13.     string str_month;
  14.     string date;
  15.  
  16. public:
  17.     numvalue(string input) : date(input){};
  18.  
  19.     ushort getmonth()
  20.      {
  21.         str_month = date.substr(0,3); //get first 3 chars
  22.  
  23.         if (str_month == "Jan") month = 1; //get month values
  24.         else if (str_month == "Feb") month = 2;
  25.         else if (str_month == "Mar") month = 3;
  26.         else if (str_month == "Apr") month = 4;
  27.         else if (str_month == "May") month = 5;
  28.         else if (str_month == "Jun") month = 6;
  29.         else if (str_month == "Jul") month = 7;
  30.         else if (str_month == "Aug") month = 8;
  31.         else if (str_month == "Sep") month = 9;
  32.         else if (str_month == "Oct") month = 10;
  33.         else if (str_month == "Nov") month = 11;
  34.         else month = 12;
  35.  
  36.         return month;
  37.     };
  38.  
  39.     ushort getday()
  40.     {
  41.         number = date.at(5);
  42.         day = (int) number - 48;
  43.         number = date.at(4);
  44.         day += 10 * ((int) number - 48);
  45.  
  46.         return day;
  47.     };
  48.  
  49.     ushort getyear()
  50.     {
  51.         number = date.at(11);
  52.         year = (int) number - 48;
  53.         number = date.at(10);
  54.         year += 10 * ((int) number - 48);
  55.         number = date.at(9);
  56.         year += 100 * ((int) number - 48);
  57.         number = date.at(8);
  58.         year += 1000 * ((int) number - 48);
  59.  
  60.         return year;
  61.     };
  62. };
  63.  
sourcetxt.h
Expand|Select|Wrap|Line Numbers
  1. #include <string>
  2. #include "curl/curl.h"
  3. #include "curl/easy.h"
  4.  
  5. using namespace std;
  6.  
  7. CURLcode copy(const string& url, const string& filepath);
  8.  
  9. size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) 
  10. {
  11.     size_t written;
  12.     written = fwrite(ptr, size, nmemb, stream);
  13.     return written;
  14. }
  15.  
  16. CURLcode copy(const string& url, const string& filepath)
  17. {
  18.  
  19.     struct cleaner
  20.     {    
  21.         FILE *fp;
  22.         ~cleaner(){fclose(fp);}
  23.     }cleanfile;
  24.  
  25.     CURLcode res;
  26.  
  27.     CURL *curl = curl_easy_init();
  28.  
  29.     if(curl) {
  30.         cleanfile.fp = fopen(filepath.c_str(),"wb");
  31.         curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  32.         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); 
  33.         curl_easy_setopt(curl, CURLOPT_WRITEDATA, cleanfile.fp);
  34.         res = curl_easy_perform(curl);
  35.         curl_easy_cleanup(curl);
  36.     }
  37.  
  38.     return res;
  39. }
  40.  
txtfiles.h
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <string>
  5. #include "sourcetxt.h"
  6. #include "dateclass.h"
  7.  
  8. using namespace std;
  9.  
  10. const string prntpath = "C:\\data1.txt";
  11.  
  12. class txtfiles
  13. {
  14. private:
  15.     CURLcode crl;
  16.     dateclass c_date;
  17.     size_t j;
  18.     string today, date, open, high, low, close, volume, search;
  19.     ifstream infile;
  20.     ofstream outfile;
  21.     ushort i;
  22. public:
  23.     txtfiles()
  24.     {
  25.         today = c_date.getcurdate();
  26.         crl = copy("http://www.google.com/finance/historical?/q=NYSE:GS", prntpath);
  27.     };
  28.  
  29.     const int& organize()
  30.     {
  31.         i = 0;
  32.         infile.open(prntpath);
  33.         outfile.open("C:\\data.txt");
  34.  
  35.         if (infile.fail())
  36.         {
  37.             cout << "Error: Could Not Open Input File!";
  38.             return 1;
  39.         }
  40.  
  41.         cout << "Successfully Opened Input File." << endl;
  42.  
  43.         while (!infile.eof())
  44.         {
  45.             getline(infile, date);
  46.             search = ", 20";
  47.  
  48.             while ((j = date.find(", 20")) != string::npos)
  49.             {
  50.                 date.replace(j, 4, "abcd");
  51.                 date.erase(0, 15);
  52.             }
  53.             while ((j = date.find("abcd")) != string::npos)
  54.             {
  55.                 i++;
  56.                 date.replace(j, 4, ", 20");
  57.                 if(i <= 5) continue;
  58.                 getline(infile, open);
  59.                 open.erase(0, 16);
  60.                 getline(infile, high);
  61.                 high.erase(0, 16);
  62.                 getline(infile, low);
  63.                 low.erase(0, 16);
  64.                 getline(infile, close);
  65.                 close.erase(0, 16);
  66.                 getline(infile, volume);
  67.                 volume.erase(0, 19);
  68.                 outfile << "[" << date << "]";
  69.                 outfile    << "[" << open << "]"; 
  70.                 outfile    << "[" << high << "]"; 
  71.                 outfile    << "[" << low << "]"; 
  72.                 outfile << "[" << close << "]"; 
  73.                 outfile << "[" << volume << "]" << endl;
  74.             }
  75.         }
  76.         infile.close();
  77.         outfile.close();
  78.         i = remove("C:\\data1.txt");
  79.         if (i == 0)
  80.         {
  81.             cout << " - Successfully Adapted Text File." << endl;
  82.             return 0;
  83.         }
  84.         else
  85.         {
  86.             cout << " - Error: Could Not Adapt File!" << endl;
  87.             return 1;
  88.         }
  89.     };
  90.  
  91.     const string& getvalue(ushort offset, char choice)
  92.     {
  93.         date = c_date.decrement(offset);
  94.         return date;
  95.     };
  96. };
  97.  
The program runs through main.cpp, sourcetxt.h, and txtfiles.h, but gives me the error message at line 12 of sourcetxt.h

I notice that ptr, cnt, base, flag, file, charbuf, bufsiz, tmpfname give the error:

CXX0030: Error: expression cannot be evaluated

If anyone can help me out, or if I am completely in the wrong section, please let me know. Thank you.
Mar 1 '11 #1

✓ answered by Banfa

Perhaps write_data is never called. That would be easy enough to check, In fact you could record how many bytes of data should have been written by adding a global (not best practice but this is debug code) integer variable and updating it in write_data with the amount of data that should have been written.

8 8420
Banfa
9,065 Expert Mod 8TB
Line 30, sourcetxt.h you need to check that fopen does not return NULL
Mar 1 '11 #2
newb16
687 512MB
Windows 7 will not allow you (a non-elevated app) to create file in the root of the disk.
Mar 1 '11 #3
Alex T
29
How would I do that though? I don't understand how to do this.
Mar 1 '11 #4
Banfa
9,065 Expert Mod 8TB
fopen just returns a pointer to file, that you store in cleaner.fp, just compare it to NULL (or 0) using == as you would with any other pointer (or other variable type).
Mar 1 '11 #5
Alex T
29
The program now finishes running, but the text file returned is empty. Why does this happen?
Mar 1 '11 #6
Banfa
9,065 Expert Mod 8TB
How do you know the text file is empty?

For example do you open it in Notepad or do you pull up the file properties and see it has a size of 0?

If you have just opened it in notepad then do pull up the file properties and look at the actual file size.

I ask this because fwrite writes binary data and given that write_data takes an object size and a number of objects it seems to me that there is nothing in the code that suggests that the output would be text.
Mar 2 '11 #7
Alex T
29
The size is 0 bytes, I just checked. I don't understand how this is.
Mar 2 '11 #8
Banfa
9,065 Expert Mod 8TB
Perhaps write_data is never called. That would be easy enough to check, In fact you could record how many bytes of data should have been written by adding a global (not best practice but this is debug code) integer variable and updating it in write_data with the amount of data that should have been written.
Mar 2 '11 #9

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

Similar topics

1
by: Kostatus | last post by:
When I close my program and call: delete *iter2; (iter2 being an iterator of a vector which contains pointers to objects) I get a "Debug Assertion Failed!" message (using VC++ 6) with the...
0
by: Guohui He | last post by:
Hi All, I am trying to update our application from VC 6.0 to VC 7.1 (.NET 2003) as managed extension. Now the compilation seems to be fine and the release version works also. However, when I run...
5
by: Ron Louzon | last post by:
I have some C++ code that uses the CSingleLock( CCriticalSection *) constructor. In visual C++ 6.0, this code compiles and runs fine in both Debug and release modes. However, in Visual Studio...
9
by: Bern McCarty | last post by:
I am porting stuff from MEC++ syntax to the new C++/CLI syntax. Something that we did in the old syntax that proved to be very valuable was to make sure that the finalizer would purposefully...
2
by: rsr | last post by:
hi, I am unable to execute my application though I am able to build and compile it without warnings or errors, because of this. Debug Assertion failure file tcscat_s.inl line: 42 can...
22
by: kudruu | last post by:
Hello, I am having a problem in Microsoft Visual C++ with some code I have written (I am a bit of a novice so I appologize if this is a very mundane problem). This is a segment from one of the...
1
by: aalam | last post by:
class base { int a; base(int x) { a=x; } ~base(); } class derive:public base
1
by: davidgale | last post by:
I'm trying to read from a text file. It gives me this error message: Debug Assertion Failed! Program: F:\Debug\lab1431.exe File: fscanf.c Expression: stream != NULL 70+ LOC Removed
2
by: Gone With Wind | last post by:
I am a novice of C++. I write the following code to append strings to a Combox (m_RibNum). This control component is on a PropertyPage hosted on a PropertySheet. int i; char buffer; CString s...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.